2011-09-17 33 views
2

您好我正在使用內置Google Map來顯示路由到用戶。 當我點擊get route按鈕時,我寫下了下面的代碼。從意圖調用另一個應用程序終止正在運行的應用程序

String mapURL="http://maps.google.com/mapssaddr=" 
+GlobleVeriable.getCurrentLocation().getLatitude()+","+GlobleVeriable.getCurrentLocation().getLongitude()+"&daddr="+restaurant.getLatitude() 
+","+restaurant.getLongitude(); 

Intent i=new Intent("android.intent.action.VIEW",Uri.parse(mapURL)); 
startActivity(i); 

此代碼工作正常,也顯示路線從當前位置到目的地的位置.. 我回來的時候,從谷歌地圖我的申請,我的應用從第一次啓動。

任何人都可以建議我該怎麼做?

+1

您是否嘗試過startActivity(I)的startActivityForResult(I)istead的代碼? – user370305

+1

當你從Google地圖返回時,你想要發生什麼? –

回答

1

能否請您嘗試以下

String uri="http://maps.google.com/mapssaddr=" 
+GlobleVeriable.getCurrentLocation().getLatitude()+","+GlobleVeriable.getCurrentLocation().getLongitude()+"&daddr="+restaurant.getLatitude() 
+","+restaurant.getLongitude(); 
    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri); 
       intent.setClassName("com.google.android.apps.maps", 
         "com.google.android.maps.MapsActivity"); 
       startActivity(intent); 
1

這只是一般的Android行爲。您可以執行的操作是在開始Google地圖活動之前將應用程序的當前狀態保存到某個文件中。恢復時,您可以加載該文件並手動恢復應用程序。

我認爲這是唯一的方法。我瀏覽Android文檔已經有一段時間了。我記得像「......操作系統可能會隨時終止您的應用程序,如果處於非活動狀態,所以開發人員有責任在應用程序不活動之前保存任何用戶敏感信息」。

我會保存在onPause()方法中,並在onResume()中加載。

相關問題