1

I have MainActivity with a fragment on it, when user clicking on fragment, user will navigate to another fragment, on the last fragment there is a button to launch google map navigation, this is the code:

@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);
}

The problem is, after map is launched I want user to back to my application when pressing back, instead to launcher.

Is there any way to do this.

This is my full code:

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
nyongrand
  • 618
  • 10
  • 24
  • after start activity write code for getActivity().onBackpressed(); – Himeshgiri gosvami Aug 31 '17 at 14:00
  • You can Use google maps within your app https://developers.google.com/maps/documentation/android-api/start . In case you cant find the soln. – Sahdeep Singh Aug 31 '17 at 14:07
  • @HimeshGoswami doesn't – nyongrand Aug 31 '17 at 14:09
  • @SahdeepSingh actually I already do that, I want Google map turn by turn navigation feature so I launch google map. – nyongrand Aug 31 '17 at 14:12
  • @nyongrand This might work https://stackoverflow.com/questions/24531391/is-it-possible-to-create-turn-by-turn-gps-navigation-app-on-android-using-google but for your question i cant say anything – Sahdeep Singh Aug 31 '17 at 14:17
  • @SahdeepSingh thanks for the link, I think it's possible, I don't pay much attention to it, because it's really simple invitation apps to show the location, it will be overkill to implement those code :) – nyongrand Aug 31 '17 at 14:27

1 Answers1

1

You have to add flags to the intent as below

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);

Please try and let me know.

  • Doesn't work, when pressing back on google map, android just back to launcher. – nyongrand Aug 31 '17 at 14:14
  • try without overriding the transaction getActivity().overridePendingTransition(R.anim.slide_up_in, R.anim.slide_up_out); – Programming Pirate Aug 31 '17 at 14:17
  • this worked fine for me, even without flags it works fine.. might be we are looking at the wrong place... are you getting any warning or exception. Did you add any flags to your mainactivity like exclude from recents in intent or in manifest? – Programming Pirate Aug 31 '17 at 14:19
  • it works on my first try, but when I try it again, without changing any code, it does not work, even after clearing all recent apps, it still does not work, – nyongrand Aug 31 '17 at 14:21
  • Please check are there any flags set for the main activity, what are the codes that are there to navigate from one fragment to other? did you call finish some where? Is your app visible in the recents after opening google maps? Is your onDestroy called? what log are you getting? I am asking you these many questions as the code snippet you have provided is not sufficient to answer your question. Sorry for asking so many questions.. – Programming Pirate Aug 31 '17 at 14:31
  • Ok, I updated my question, myl app is visible on the recet, onDestroy is not called, – nyongrand Aug 31 '17 at 14:42
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/153380/discussion-between-programming-pirate-and-nyongrand). – Programming Pirate Aug 31 '17 at 14:43