Android 从谷歌地图回来后恢复我的应用程序

Android 从谷歌地图回来后恢复我的应用程序,android,cordova,google-maps,android-activity,Android,Cordova,Google Maps,Android Activity,我想在谷歌地图中显示一个位置,为此我使用了以下代码: String geo = maindata.getString("map"); String uri = String.format(Locale.ENGLISH, geo, "", ""); final Intent intent1 = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); try { cordova.getActivity().runO

我想在谷歌地图中显示一个位置,为此我使用了以下代码:

    String geo = maindata.getString("map");
    String uri = String.format(Locale.ENGLISH, geo, "", "");
    final Intent intent1 = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
    try {
       cordova.getActivity().runOnUiThread(new Runnable() {
         public void run() {
cordova.getActivity().startActivity(intent1);
}
     });
   }catch(Exception e){
        e.printStackTrace();
   }
谷歌地图应用程序正在启动,它也显示了正确的位置, 但问题是,当按下后退按钮时,它正在重新启动我的应用程序


鉴于我想从午餐位置恢复,你必须将你的活动放到堆栈的底部,然后启动谷歌地图应用程序活动

请执行以下操作:

        String geo = maindata.getString("map");
String uri = String.format(Locale.ENGLISH, geo, "", "");
final Intent intent1 = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
try {
     TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class); //Instead Of MainActivity you can add your Launching activity Name
    stackBuilder.addNextIntent(intent1);
   cordova.getActivity().runOnUiThread(new Runnable() {
     public void run() {
    startActivity(intent1);
 }
      });
    }catch(Exception e){
    e.printStackTrace();
   }

您可以使用以下代码段在google地图上显示特定位置:

Uri gmmIntentUri = Uri.parse("google.navigation:q=" + lattitude+ ","
                            + longitude+ "+&mode=d");
                    Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
                    if (isAppInstalled("com.google.android.apps.maps")) {

                        mapIntent.setClassName("com.google.android.apps.maps",
                                "com.google.android.maps.MapsActivity");
                    }
                    startActivity(mapIntent);
这里的纬度和经度属于您要在地图上显示的位置

 /**
 * helper function to check if Maps is installed
 **/


 private boolean isAppInstalled(String uri) {
        PackageManager pm = mActivity.getPackageManager();
        boolean app_installed = false;
        try {
            pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
            app_installed = true;
        } catch (PackageManager.NameNotFoundException e) {
            app_installed = false;
        }
        return app_installed;
    }
在谷歌地图的背面按下按钮时,用户将重定向到谷歌地图启动的同一活动