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 6967551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:20:11+00:00 2026-05-27T16:20:11+00:00

What I am trying to say here is the problem I’m facing to relaunch

  • 0

What I am trying to say here is the problem I’m facing to relaunch my app from same state where it was left before. I have did lot of R&D on this and have gone through the questions posted in stackoverflow.So please it is not necessary to say that it is a duplicate.

I tried putting these options
objIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
while starting the activity. Also I have tried this,

objIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 

And finally I tried this method also

    objIntent.setAction(Intent.ACTION_MAIN);
    objIntent.addCategory(Intent.CATEGORY_LAUNCHER); 

But none of these seem to be working for me.

The scenario goes like this, where this fails.

  1. I run my application, go to some activity from the initial activity say from A to B

  2. Now I will press my phone home button and do some actions like clicking photo and etc.

  3. Again I try to launch the app from home screen.

Oops!! Now my app has not retained its state, it is launching from the initial state.

Note:

  1. However this is not true in all the cases. some times say around 1 or 2 times out of 10 or 15 times, it launches from the same state where it was left before.

  2. One more doubt i have is do I need to set this for all the intents? Say i have some 10+ positions of Intent i.e., starting the activity. Do I need to add this piece of code in all those places? I included this for 2 or 3 cases

Update:

This works in the debug mode, but when it comes to the point of an apk create, it is getting failed. However, if I try number of times it gives me the required result and there after behaves in the way as expected. Breaking my head to understand why it happening like this.

Any one has the answer for this?

  • 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-05-27T16:20:12+00:00Added an answer on May 27, 2026 at 4:20 pm

    Yes, finally it is possible!! Thanks to google forum. I referred this https://github.com/cleverua/android_startup_activity.

    What I did according to this is, create a startup activity. Inside it’s oncreate method, check for a custom method called needStartApp() or something with your convention. In this get the running tasks info and compare it with our application package name. And if it is true, start your initial activity. Rest everything goes fine.

    Here is the extra activity you should add,

    public class StartupActivity extends Activity {
    
     @Override
     protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        if (needStartApp()) {
            Intent i = new Intent(StartupActivity.this, MainActivity.class);
            startActivity(i);
        }
    
        finish();
    }
    
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        // this prevents StartupActivity recreation on Configuration changes 
        // (device orientation changes or hardware keyboard open/close).
        // just do nothing on these changes:
        super.onConfigurationChanged(null);
    }
    
    private boolean needStartApp() {
        final ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        final List<RunningTaskInfo> tasksInfo = am.getRunningTasks(1024);
    
        if (!tasksInfo.isEmpty()) {
            final String ourAppPackageName = getPackageName();
            RunningTaskInfo taskInfo;
            final int size = tasksInfo.size();
            for (int i = 0; i < size; i++) {
                taskInfo = tasksInfo.get(i);
                if (ourAppPackageName.equals(taskInfo.baseActivity.getPackageName())) {
                    // continue application start only if there is the only Activity in the task
                    // (BTW in this case this is the StartupActivity)
                    return taskInfo.numActivities == 1;
                }
            }
        } 
    
        return true;
       }
     }
    

    At the end, do not forget to add this permission to the manifest

        <uses-permission android:name="android.permission.GET_TASKS" />
    

    “Android OS is really good, however it is not perfect.”

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

Sidebar

Related Questions

Here's the coding problem I am trying to solve... I have a base class,
I have a unique problem/situation here. Trying to make it as simple as possible.
I have a problem here which i am trying to solve. The program is
I have a problem here with the php function substr Let's say I have
Trying to avoid the SomethingManager trap here... Let's say I'm going to write a
Let's say i have a Domain Model that im trying to make compatible with
I'm trying to do the following say; I have a hash: {word1 => {doc1
I am trying to create an implicit conversion from any type (say, Int) to
I'm having a problem here trying to upload a file with powershell. What I'm
Ok, so here's my problem. We are looking at purchasing a data set from

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.