Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9004151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:50:14+00:00 2026-06-16T00:50:14+00:00

I am not really familiar with intent flags, so please, bear with me. I

  • 0

I am not really familiar with intent flags, so please, bear with me.

I am doing an application which displays stuff from a database in a ViewPager. I also have a widget which from time to time pulls out a random row and displays it. Now, when I click on it, I am taken to an activity where the same content is displayed and now I can take action on it.

Everything works, however when I have an activity already running and then click on the widget, it seems it creates a new instance, because when I press the Back button I am not exiting the application but am taken to the previous instance or something.

Is there a way to start a new instance of an activity and if there were some previous instances running close them, using flags?

I played around with CLEAR_TOP and that stuff but I honestly don’t know what am I doing.

Thanks!

//EDIT

Intent.FLAG_ACTIVITY_CLEAR_TOP doesn’t seem to do anything. Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP seems to bring the previous one to the top and ignores the new one or something. Maybe let me rephrase, I start the activity from launcher icon, then I press the Home button and click on widget and it should bring up a new instance where ViewPager.setCurrentItem sets the correct page (same as in widget). If there were no main activity running before, everything is okay, but if it was running, finish 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);
        //intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
        views.setOnClickPendingIntent(R.id.widget_container, pendingIntent);

        appWidgetManager.updateAppWidget(appWidgetId, views);
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:50:15+00:00Added an answer on June 16, 2026 at 12:50 am

    There are several ways to do this. If you want to create a new instance and close the current instance (assuming that it is on the top of the activity stack) you need to set Intent.FLAG_ACTIVITY_CLEAR_TOP.

    Another alternative would be to reuse the same instance of the activity if it is already on the top of the stack. In this case you need to set both Intent.FLAG_ACTIVITY_CLEAR_TOP and Intent.FLAG_ACTIVITY_SINGLE_TOP. If you do this, Android won’t create another instance of the activity, but will call onNewIntent() of your activity to deliver the new Intent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having an issue with flash, which I am not really familiar with. I'm
OK, first off, I am NOT really familiar with javascript, so please forgive if
Little help please, because I am not really familiar with this kind of thing.
I am creating a phonegap application for android. I am not really familiar with
I'm having trouble with some syntax. I'm not really familiar with interfaces so please
I'm not really familiar with creating generic methods, so I thought I'd put this
i'm really not very familiar with CSS and HTMl so take it easy with
I'm not too familiar with Linux/Bash, so I can't really find the right terms
I'm writing a java binding for a C code and I'm not really familiar
Im not really familiar with how this works in JSP but in the main.jsp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.