سؤال

1.install an apk from app installer 2.then just click "OPEN" to launch it at once 3.after the app launched and then press HOME key 4.find the app from app list and click its icon to launch again 5.then the app will be launched with a new instance. And if you repeat 3~5 several times, it will repeat create a new instance. if you press "BACK" key now, you will see the app is still there for the same times you launched.

But if you just click "DONE" at step 2 and then launch the app from app list, everything will be OK then. Why?

هل كانت مفيدة؟

المحلول

The app installer (as well as many Android IDEs) use different intent flags than the regular app launcher does, which means that the launcher's intent doesn't properly match with the Activity's existing intent and it ends up creating a new activity on top of the stack.

I think this question is similar to what you're asking about:

Activity stack ordering problem when launching application from Android app installer and from Home screen

نصائح أخرى

This solution worked for me. It checks if the app was launched in this way then finishes the activity. This leaves the the activity that should have been started and brings it to the front.

 private void checkIfActivityShouldBeFinished() {
   if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) { 
     // Activity was brought to front and not created,  
     // Thus finishing this will get us to the last viewed activity  
     finish(); 
     return;  
   }  
 }

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top