I am not very familiar with the flags of intent, so please carry me.
I am making an application that displays material from a database in ViewPager. I also have a widget that from time to time draws a random string and displays it. Now, when I click on it, they take me to activity, where the same content is displayed, and now I can take action on it.
Everything works, however, when I have already started work, and then click on the widget, it seems that it creates a new instance, because when I click the "Back" button, I do not exit the application, but I got to the previous instance or what something.
Is there a way to start a new instance of the action, and if there were some previous instances that close them using flags?
I played with CLEAR_TOP and that, but I honestly don't know what I'm doing.
Thanks!
// EDIT
Intent.FLAG_ACTIVITY_CLEAR_TOP does not seem to be doing anything. Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP seems to bring the previous vertex and ignores the new or something else. Perhaps let me rephrase, I start the action from the start icon, then click the "Home" button and click on the widget, and it should output a new instance, where ViewPager.setCurrentItem sets the correct page (same as in widgets). If before there was no main activity, everything is fine, but if it was started, complete it.
MyWidgetProvider extends AppWidgetProvider @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { Log.d("MainActivity", "MyWidgetProvider # onUpdate"); for (int i = 0; i < appWidgetIds.length; i++) { int appWidgetId = appWidgetIds[i]; Intent intent = new Intent(context, MainActivity.class); intent.putExtra("from_widget", true);