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

后端 未结 3 897
悲&欢浪女
悲&欢浪女 2020-12-04 08:47

For testing purposes only, I am allowing my app APK to be downloaded and installed via a URL. Once downloaded on the phone, it can be launched with the Android app installer

相关标签:
3条回答
  • 2020-12-04 09:02

    Added the answer that antonyt provided:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        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;
        }
    
        // Regular activity creation code...
    }
    
    0 讨论(0)
  • 2020-12-04 09:23

    Your problem is likely rooted in the fact that App installer doesn't use the LAUNCHER category, as does the launcher.

    This bug has been documented elsewhere:

    App always starts fresh from root activity instead of resuming background state (Known Bug)

    0 讨论(0)
  • 2020-12-04 09:24

    The underlying issue I believe is that the Intents used are different between the launcher and the installer. In so far as you are getting different Intent flags you are going to get different launch behavior. You can muck with the launch modes and you may be able to get a consistent result but fundamentally those different Intents will produce different results.

    Your fix (or something like this) is probably your best bet.

    0 讨论(0)
提交回复
热议问题