Alternative to Intent.FLAG_ACTIVITY_CLEAR_TASK

后端 未结 6 1098
傲寒
傲寒 2021-02-06 22:59

I have two apps App-B launches App-A. If the user starts App B from inside App A I call finish on App-A so I have no problem.

If the user goes straight to App B from th

6条回答
  •  一个人的身影
    2021-02-06 23:16

    I'm still having a lot of trouble understanding the problem but would like to help you fix it. Since comments only allow 600 characters and don't format well, I'm going to create an answer instead, because I'm sure that together we can get this resolved.

    I would like to be able to reproduce your problem. To do that I've created 2 applications: AppA and AppB. AppA has a single activity called ActivityA and AppB has a single activity called ActivityB. Both ActivityA and ActivityB use android:launchMode="singleTask".

    ActivityA has a button on it that launches AppB and finishes, like this:

        Intent intent = new Intent("de.sharpmind.example.AppB");
        intent.putExtra("extra", "launched from AppA");
        startActivity(intent);
        finish();
    

    ActivityB has a button on it that launches AppA like this:

        Intent intent = new Intent("de.sharpmind.example.AppA");
        intent.putExtra("extra", "launched from AppB");
        startActivity(intent);
    

    This all works as I expect it to. AppA and AppB run in different tasks. The "extra" is properly seen in the onCreate() methods of each application.

    So, can you please tell me more about your problem. How can I reproduce exactly your problem? You wrote:

    On lower APIs the new task in APP-A will not change and extras putExtra will have no effect.

    What do you mean by that? Where are you putting extras and where are you getting them and what do you expect to happen?

    Also, what is the launchMode of your AppB?

    Also, when you have this problem, are there other activities in the task stack for AppA?

    Please provide more info, either in your original question or here as comments.

提交回复
热议问题