How to clear task and start new activity from widget

295
August 11, 2017, at 07:02 AM

I have an application with the following activities

MainActivity > DetailActivity

If I start the DetailActivity from the MainActivity using the following flags in my intent

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);

The current task will be cleared and a new task will be started with only DetailActivity on the stack.

However, if I currently have MainActivity on the stack, and I start a new instance of MainActivity from the a widget using the same flags, I get two instances of MainActivity overlaying each-other.

Is it not possible to clear the task and start a new instance of MainActivity from the widget?

Answer 1

Use Launcher more android:launchMode="singleTop" in MainActivity, if you open MainActivity again from widget it will just call onNewIntent method.

Rent Charter Buses Company
READ ALSO
Ubuntu Android emulator not starting up

Ubuntu Android emulator not starting up

For two days, I have been trying to make my android emulator work by doing what other people on the internet did but nothing seems to workI tried choosing Software GLES 2

405
Add text to android drawable xml

Add text to android drawable xml

I am trying to use an android drawable xml

434
Google Maps Webview Mock Location

Google Maps Webview Mock Location

I'm developing an app on Android and I'm trying to use this app for location mock on Android 60

390
How to avoid fragment duplication issue?

How to avoid fragment duplication issue?

I have the following code:

273