Question

I have several widgets from one app and when user clicks widget I want to open an activity where he can edit that "note". I start the Activity like this:

Intent openCounter = new Intent(context, CounterEditActivity.class);
openCounter.putExtra(CounterEditActivity.COUNTER_ID, counter_id);
openCounter.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(openCounter);

It works correctly when the whole application is running (you click home button, click on on widget, click home, click on another widget).

Problem starts when the app is not running (it doesn't show up in the Task Manager). Then when you first click on a widget, it opens the right activity. However if you click home and click on another widget, it opens the already running activity from the first widget.

Any ideas how to achieve such behaviour?

Was it helpful?

Solution

If your goal is to forcefully start a new activity whenever the widget is tapped, you might want to add an additional flag:

openCounter.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

Note that this is only available starting from API level 11, though.

If that doesn't help, please try adding

android:launchMode="singleTask"

to the CounterEditActivity activity tag in the manifest and see if that doesn't force a new activity to start.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top