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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:58:52+00:00 2026-05-28T06:58:52+00:00

Evening, I’m facing a small problem which I can’t get fixed. I’m having one

  • 0

Evening,

I’m facing a small problem which I can’t get fixed. I’m having one ‘base’ activity (name: TestActivity, extending ActivityGroup) with a history array list in it. Every time when I’m going to a new activity I’m using the following bit to load a new view.

Intent intent = new Intent(Start.this, CitySelect.class);
View view = TestActivity.group.getLocalActivityManager().startActivity("cityselect", intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
TestActivity.group.replaceView(view); 

As you can see I’m calling the replaceView method to ‘replace’ the view. See below for the code:

public void replaceView(View v)
{
    history.add(v);
    setContentView(v);
}

In every activity I’m overriding the onBackPressed:

@Override
public void onBackPressed()
{
    TestActivity.group.back();
}

See below for the back method:

public void back()
{
    if (history.size() > 0)
    {
        history.remove(history.size() - 1);

        if (history.size() > 0)
        {
            View v = history.get(history.size() - 1);
            setContentView(v);
        }

        else
        {
            finish();
        }
    }

    else
    {
        finish();
    }
} 

Now comes the problem: when I’m using the back button on my phone and the previous activity comes to the foreground nothing will be called in the view (activity). When I follow the Activity life cyle I thought that the onResume will be called but that’s not the case. Nothing happens.

So the question is: How can I call the onResume method when I’m pressing the back button?

  • 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-28T06:58:53+00:00Added an answer on May 28, 2026 at 6:58 am

    @Commonsware kindly pointed out (in another post of mine) that ActivityGroups have actually been deprecated. We are supposed to be moving onto to Fragments, instead.

    Been battling with the same problem as you for longer than I care to admit. None of the commonly used tools (OnResume, OnRestart) work when you return the focus to a view from within an ActivityGroup after pressing the back button.

    Unfortunately, I still need to find a way to fake an onResume when the from within the ActivityGroup after the back button is pressed (since I am heavily invested in this legacy code that uses ActivityGroups.) On I struggle.

    Hope this helps.

    — edit —

    I found a way to do this:

    Instead of keeping a history of the views, keep a history of the id’s of the the activities you start. Every activity you start has a unique id associated with it. So, when you call back(), retrieve the activity’s id, and start the activity anew. This will trigger your activity’s “onResume()” method as you desire.

    Here is how I would restructure the code you provided:
    following bit to load a new view:

    Intent intent = new Intent(Start.this, CitySelect.class);
    View view =     TestActivity.group.getLocalActivityManager().startActivity("cityselect", intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
    TestActivity.group.replaceView(view,"cityselect"); 
    

    Replacing the view within the “replaceView()” method:

    public void replaceView(View v, String activityId)
    {
        history.add(activityId);
        setContentView(v);
    }
    

    And finally, the back() method from within the ActivityGroup:

    public void back()
    {
    if (history.size() > 0)
    {
        history.remove(history.size() - 1);
    
        if (history.size() > 0)
        {
            //View v = history.get(history.size() - 1);
            //setContentView(v);
    
           LocalActivityManager manager = getLocalActivityManager();
           String lastId = mIdList.get(history.size()-1);
           Intent lastIntent = manager.getActivity(lastId).getIntent();
           Window newWindow = manager.startActivity(lastId, lastIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
           setContentView(newWindow.getDecorView());
    
        }
    
        else
        {
            finish();
        }
    }
    
    else
    {
        finish();
    }
    

    }

    Hope THIS helps a little more 🙂

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

Sidebar

Related Questions

Good evening, i need to know how can i have one .h file that
Evening :) I have a little problem... As you can see in my code
Evening, Is there a common or standardised name given to a function or method
Good evening I've got a little problem with my DataGridView in a .NET Windows
Good evening guys, how can I run a piece of jQuery/ajax when a certain
Good evening, In a test JSF 2.0 web app, I am trying to get
Good evening, I have one table, with a timestamp column, then I have a
Good evening, I am having a weird issue with a method I am trying
good evening. ingore all other elements, I want get first image in each foreach.
Good Evening, I'm building a website which will will look something like this: So

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.