0

My app (app A) has options to send location data either to

  • Google Maps, or to
  • an app (app B) that I have written to display topographical maps

The code in app A for calling the two apps is essentially identical

btnGoogleMap.setOnClickListener {
    var uriString =
        "geo:0,0?q=$selectedPoiLatitude,$selectedPoiLongitude&z=11"
    var gmmIntentUri =
        Uri.parse(uriString)
    val googleMapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri)
    googleMapIntent.setPackage("com.google.android.apps.maps")
    startActivity(googleMapIntent)
}

btnMyMap.setOnClickListener() {
    var mmUriString = "latlong:$selectedPoiLatitude,$selectedPoiLongitude"
    var mmIntentUri = Uri.parse(mmUriString)
    val mmIntent = Intent("com.prepbgg.mymap.action.latlong",mmIntentUri)
    mmIntent.setPackage("com.prepbgg.mymap")
    startActivity(mmIntent)
}

After using the option to call app B (mymap), the task switcher shows the same thumbnail (of the map displayed in app B) for app A as well as for app B. If I then use the task switcher to reopen app A it opens with the map from app B displayed. The same happens if I reopen app A from the Home screen or the app drawer. I have to use the back button to get app A to display its own screen.

If I call Google Maps from app A, the task switcher shows different thumbnails as I would expect: a thumbnail of Google Maps for Google Maps and a thumbnail of app A's screen for app A and that is what I see if I reopen app A.

How can I get the same behaviour when calling app B as I get when calling Google Maps?

prepbgg
  • 3,564
  • 10
  • 39
  • 51
  • 1
    Google Maps probably has set a task affinity or launch mode on that activity to have it be part of the Maps task. App B has not, and the default behavior is for an activity to belong to the task of the activity that launched it. – CommonsWare Jun 27 '20 at 20:19
  • Thanks. I'll look into task affinities and launch modes to see whether I can change the behaviour. – prepbgg Jun 27 '20 at 20:33
  • Inserting `mmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)` into App A's code seems to have done the trick. Now I have to see is there are any unwanted side-effects. – prepbgg Jun 28 '20 at 16:31

0 Answers0