2017-08-31 85 views
1

我有一個片段的MainActivity,當用戶點擊片段,用戶將導航到另一個片段,最後一個片段有一個按鈕來啓動谷歌地圖導航,這是代碼:啓動谷歌地圖意圖後返回到活動

@Override 
public void onClick(View v) { 
    String url = "https://www.google.com/maps/dir/?api=1&destination=-17.174498,12.634206"; 
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
    startActivity(intent); 
    getActivity().overridePendingTransition(R.anim.slide_up_in, R.anim.slide_up_out); 
} 

問題是,地圖啓動後,我想用戶回到我的應用程序時,按回來,而不是發射。

有沒有辦法做到這一點。

這是我的全碼:

MainActivity

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     setTheme(R.style.AppTheme); 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     if (savedInstanceState == null) { 
      getFragmentManager().beginTransaction() 
        .replace(R.id.fragment_container, new SplashFragment()) 
        .commit(); 
     } 
    } 
} 

SplashFragment

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    // Inflate the layout for this fragment 
    View view = inflater.inflate(R.layout.fragment_splash, container, false); 
    view.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      Transition transition = new Fade(Visibility.MODE_IN); 
      transition.setDuration(400); 

      Fragment fragment = MapsFragment.newInstance(); 

      // set transition animation 
      fragment.setEnterTransition(transition); 
      fragment.setAllowEnterTransitionOverlap(true); 
      fragment.setAllowReturnTransitionOverlap(true); 

      // add second fragment by replacing first 
      getFragmentManager().beginTransaction() 
        .replace(R.id.fragment_container, fragment) 
        .addToBackStack(null) 
        .commit(); 
     } 
    }); 

    return view; 
} 

LOG

08-31 21:45:41.072 1536-1536/? E/Zygote: v2 
08-31 21:45:41.072 1536-1536/? I/libpersona: KNOX_SDCARD checking this for 10319 
08-31 21:45:41.072 1536-1536/? I/libpersona: KNOX_SDCARD not a persona 
08-31 21:45:41.072 1536-1536/? W/SELinux: Function: selinux_compare_spd_ram, index[1], priority [2], priority version is VE=SEPF_SECMOBILE_6.0.1_0034 
08-31 21:45:41.082 1536-1536/? E/Zygote: accessInfo : 0 
08-31 21:45:41.082 1536-1536/? W/SELinux: SELinux: seapp_context_lookup: seinfo=default, level=s0:c512,c768, pkgname=com.nyongrand.ibnuratihinvitation 
08-31 21:45:41.082 1536-1536/? I/art: Late-enabling -Xcheck:jni 
08-31 21:45:41.152 1536-1536/com.nyongrand.ibnuratihinvitation W/ResourcesManager: Resource getTopLevelResources for package com.nyongrand.ibnuratihinvitationoverlayDirs =Null 
08-31 21:45:41.342 1536-1536/com.nyongrand.ibnuratihinvitation W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.nyongrand.ibnuratihinvitation-2/split_lib_dependencies_apk.apk --oat-file=/data/dalvik-cache/arm64/[email protected]@[email protected][email protected]) because non-0 exit status 
08-31 21:45:41.592 1536-1536/com.nyongrand.ibnuratihinvitation W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.nyongrand.ibnuratihinvitation-2/split_lib_slice_0_apk.apk --oat-file=/data/dalvik-cache/arm64/[email protected]@[email protected][email protected]) because non-0 exit status 
08-31 21:45:41.652 1536-1536/com.nyongrand.ibnuratihinvitation W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.nyongrand.ibnuratihinvitation-2/split_lib_slice_1_apk.apk --oat-file=/data/dalvik-cache/arm64/[email protected]@[email protected][email protected]) because non-0 exit status 
08-31 21:45:41.712 1536-1536/com.nyongrand.ibnuratihinvitation W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.nyongrand.ibnuratihinvitation-2/split_lib_slice_2_apk.apk --oat-file=/data/dalvik-cache/arm64/[email protected]@[email protected][email protected]) because non-0 exit status 
08-31 21:45:41.782 1536-1536/com.nyongrand.ibnuratihinvitation W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.nyongrand.ibnuratihinvitation-2/split_lib_slice_3_apk.apk --oat-file=/data/dalvik-cache/arm64/[email protected]@[email protected][email protected]) because non-0 exit status 
08-31 21:45:41.842 1536-1536/com.nyongrand.ibnuratihinvitation W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.nyongrand.ibnuratihinvitation-2/split_lib_slice_4_apk.apk --oat-file=/data/dalvik-cache/arm64/[email protected]@[email protected][email protected]) because non-0 exit status 
08-31 21:45:41.902 1536-1536/com.nyongrand.ibnuratihinvitation W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.nyongrand.ibnuratihinvitation-2/split_lib_slice_5_apk.apk --oat-file=/data/dalvik-cache/arm64/[email protected]@[email protected][email protected]) because non-0 exit status 
08-31 21:45:41.972 1536-1536/com.nyongrand.ibnuratihinvitation W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.nyongrand.ibnuratihinvitation-2/split_lib_slice_6_apk.apk --oat-file=/data/dalvik-cache/arm64/[email protected]@[email protected][email protected]) because non-0 exit status 
08-31 21:45:42.032 1536-1536/com.nyongrand.ibnuratihinvitation W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.nyongrand.ibnuratihinvitation-2/split_lib_slice_7_apk.apk --oat-file=/data/dalvik-cache/arm64/[email protected]@[email protected][email protected]) because non-0 exit status 
08-31 21:45:42.092 1536-1536/com.nyongrand.ibnuratihinvitation W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.nyongrand.ibnuratihinvitation-2/split_lib_slice_8_apk.apk --oat-file=/data/dalvik-cache/arm64/[email protected]@[email protected][email protected]) because non-0 exit status 
08-31 21:45:42.162 1536-1536/com.nyongrand.ibnuratihinvitation W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.nyongrand.ibnuratihinvitation-2/split_lib_slice_9_apk.apk --oat-file=/data/dalvik-cache/arm64/[email protected]@[email protected][email protected]) because non-0 exit status 
08-31 21:45:42.162 1536-1536/com.nyongrand.ibnuratihinvitation W/System: ClassLoader referenced unknown path: /data/app/com.nyongrand.ibnuratihinvitation-2/lib/arm64 
08-31 21:45:42.172 1536-1536/com.nyongrand.ibnuratihinvitation I/InstantRun: starting instant run server: is main process 
08-31 21:45:42.322 1536-1536/com.nyongrand.ibnuratihinvitation W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable 
08-31 21:45:42.532 1536-1705/com.nyongrand.ibnuratihinvitation I/zzbx: Making Creator dynamically 
08-31 21:45:42.542 1536-1705/com.nyongrand.ibnuratihinvitation W/ResourcesManager: Resource getTopLevelResources for package com.google.android.gmsoverlayDirs =Null 
08-31 21:45:42.602 1536-1708/com.nyongrand.ibnuratihinvitation I/OpenGLRenderer: Initialized EGL, version 1.4 
08-31 21:45:42.652 1536-1542/com.nyongrand.ibnuratihinvitation W/art: Suspending all threads took: 6.789ms 
08-31 21:45:42.662 1536-1705/com.nyongrand.ibnuratihinvitation W/ResourcesManager: Resource getTopLevelResources for package com.google.android.gmsoverlayDirs =Null 
08-31 21:45:42.672 1536-1536/com.nyongrand.ibnuratihinvitation I/Timeline: Timeline: Activity_idle id: [email protected] time:16980299 
08-31 21:45:42.712 1536-1705/com.nyongrand.ibnuratihinvitation I/Google Maps Android API: Google Play services client version: 11020000 
08-31 21:45:42.732 1536-1705/com.nyongrand.ibnuratihinvitation I/Google Maps Android API: Google Play services package version: 11509440 
08-31 21:45:43.322 1536-1705/com.nyongrand.ibnuratihinvitation E/MotionRecognitionManager: mSContextService = [email protected] 
08-31 21:45:43.322 1536-1705/com.nyongrand.ibnuratihinvitation E/MotionRecognitionManager: motionService = [email protected]ea6fea3 
08-31 21:45:43.322 1536-1705/com.nyongrand.ibnuratihinvitation E/MotionRecognitionManager: motionService = [email protected]ea6fea3 
08-31 21:45:43.382 1536-1705/com.nyongrand.ibnuratihinvitation W/System.err: mkdir failed: EEXIST (File exists) : /storage/emulated/0/Android/data/com.nyongrand.ibnuratihinvitation/cache/debug 
08-31 21:45:43.382 1536-1705/com.nyongrand.ibnuratihinvitation W/System.err: mkdir failed: EEXIST (File exists) : /storage/emulated/0/Android/data/com.nyongrand.ibnuratihinvitation/cache 
08-31 21:45:43.432 1536-1793/com.nyongrand.ibnuratihinvitation I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
08-31 21:45:43.432 1536-1793/com.nyongrand.ibnuratihinvitation I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
08-31 21:45:43.442 1536-1793/com.nyongrand.ibnuratihinvitation I/qtaguid: Tagging socket 85 with tag 3000110100000000{805310721,0} uid -1, pid: 1536, getuid(): 10319 
08-31 21:45:43.842 1536-1793/com.nyongrand.ibnuratihinvitation I/qtaguid: Tagging socket 79 with tag 3000110100000000{805310721,0} uid -1, pid: 1536, getuid(): 10319 
08-31 21:45:44.002 1536-1793/com.nyongrand.ibnuratihinvitation I/qtaguid: Untagging socket 85 
08-31 21:45:57.962 1536-1536/com.nyongrand.ibnuratihinvitation I/Google Maps Android API: Google Play services package version: 11509440 
08-31 21:45:58.102 1536-1795/com.nyongrand.ibnuratihinvitation I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
08-31 21:45:58.102 1536-1795/com.nyongrand.ibnuratihinvitation I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
08-31 21:45:58.102 1536-1795/com.nyongrand.ibnuratihinvitation I/qtaguid: Tagging socket 85 with tag 3000110100000000{805310721,0} uid -1, pid: 1536, getuid(): 10319 
08-31 21:45:58.192 1536-1796/com.nyongrand.ibnuratihinvitation I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
08-31 21:45:58.192 1536-1796/com.nyongrand.ibnuratihinvitation I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
08-31 21:45:58.192 1536-1796/com.nyongrand.ibnuratihinvitation I/qtaguid: Tagging socket 58 with tag 3000110100000000{805310721,0} uid -1, pid: 1536, getuid(): 10319 
08-31 21:45:58.282 1536-1795/com.nyongrand.ibnuratihinvitation I/qtaguid: Untagging socket 85 
08-31 21:45:58.452 1536-1796/com.nyongrand.ibnuratihinvitation I/qtaguid: Tagging socket 61 with tag 3000110100000000{805310721,0} uid -1, pid: 1536, getuid(): 10319 
08-31 21:45:58.682 1536-1796/com.nyongrand.ibnuratihinvitation I/qtaguid: Untagging socket 58 
08-31 21:45:59.352 1536-1797/com.nyongrand.ibnuratihinvitation I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
08-31 21:45:59.352 1536-1797/com.nyongrand.ibnuratihinvitation I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
08-31 21:45:59.362 1536-1797/com.nyongrand.ibnuratihinvitation I/qtaguid: Tagging socket 93 with tag 3000110100000000{805310721,0} uid -1, pid: 1536, getuid(): 10319 
08-31 21:46:00.182 1536-3184/com.nyongrand.ibnuratihinvitation W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found. 
08-31 21:46:00.202 1536-3184/com.nyongrand.ibnuratihinvitation I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:4 
08-31 21:46:00.202 1536-3184/com.nyongrand.ibnuratihinvitation I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 4 
08-31 21:46:00.222 1536-3184/com.nyongrand.ibnuratihinvitation W/System: ClassLoader referenced unknown path: /data/data/com.google.android.gms/app_chimera/m/00000014/n/arm64-v8a 
08-31 21:46:00.232 1536-3184/com.nyongrand.ibnuratihinvitation W/ResourcesManager: Resource getTopLevelResources for package com.google.android.gmsoverlayDirs =Null 
08-31 21:46:01.522 1536-1797/com.nyongrand.ibnuratihinvitation I/qtaguid: Tagging socket 103 with tag 3000110100000000{805310721,0} uid -1, pid: 1536, getuid(): 10319 
08-31 21:46:01.922 1536-1797/com.nyongrand.ibnuratihinvitation I/qtaguid: Untagging socket 93 
+0

開始活動後爲getActivity()寫入代碼onBackpressed(); –

+0

您可以在您的應用程序中使用Google地圖https://developers.google.com/maps/documentation/android-api/start。如果你不能找到soln。 –

+0

@HimeshGoswami不是 – nyongrand

回答

1

你必須標誌添加到意向如下

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 
startActivity(intent); 
getActivity().overridePendingTransition(R.anim.slide_up_in, R.anim.slide_up_out); 

請嘗試,讓我知道。

+0

在谷歌地圖上按下時不起作用,Android只是回到啓動器。 – nyongrand

+0

嘗試不重寫事務getActivity()。overridePendingTransition(R.anim.slide_up_in,R.anim.slide_up_out); –

+0

這工作對我來說很好,即使沒有旗幟,它的工作正常..可能是我們正在看錯地方...你是否得到任何警告或例外。您是否在主意活動中添加了任何標誌,如意圖或清單中的最近排除內容? –