启动谷歌地图意图后返回活动

时间:2017-08-31 13:52:55

标签: android google-maps android-fragments android-intent

我的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/data@app@com.nyongrand.ibnuratihinvitation-2@split_lib_dependencies_apk.apk@classes.dex) 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/data@app@com.nyongrand.ibnuratihinvitation-2@split_lib_slice_0_apk.apk@classes.dex) 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/data@app@com.nyongrand.ibnuratihinvitation-2@split_lib_slice_1_apk.apk@classes.dex) 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/data@app@com.nyongrand.ibnuratihinvitation-2@split_lib_slice_2_apk.apk@classes.dex) 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/data@app@com.nyongrand.ibnuratihinvitation-2@split_lib_slice_3_apk.apk@classes.dex) 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/data@app@com.nyongrand.ibnuratihinvitation-2@split_lib_slice_4_apk.apk@classes.dex) 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/data@app@com.nyongrand.ibnuratihinvitation-2@split_lib_slice_5_apk.apk@classes.dex) 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/data@app@com.nyongrand.ibnuratihinvitation-2@split_lib_slice_6_apk.apk@classes.dex) 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/data@app@com.nyongrand.ibnuratihinvitation-2@split_lib_slice_7_apk.apk@classes.dex) 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/data@app@com.nyongrand.ibnuratihinvitation-2@split_lib_slice_8_apk.apk@classes.dex) 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/data@app@com.nyongrand.ibnuratihinvitation-2@split_lib_slice_9_apk.apk@classes.dex) 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: android.os.BinderProxy@9e7090d 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 = android.hardware.scontext.ISContextService$Stub$Proxy@de4bdd2
08-31 21:45:43.322 1536-1705/com.nyongrand.ibnuratihinvitation E/MotionRecognitionManager: motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy@ea6fea3
08-31 21:45:43.322 1536-1705/com.nyongrand.ibnuratihinvitation E/MotionRecognitionManager: motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy@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

1 个答案:

答案 0 :(得分: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);

请尝试让我知道。