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

  • Home
  • SEARCH
  • 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 7021475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:27:17+00:00 2026-05-27T23:27:17+00:00

I’m developing an app which contain TabHost ,in one of those tabs i have

  • 0

I’m developing an app which contain TabHost ,in one of those tabs i have an ActivityGroup , and from this ActivityGroup, i launch another SubActivity ( let’s say that i Launch an Activity A ), and until this , everything is OK.

The problem is when i press the BackButton ,the CurrentActivity( Activity A ) is destroyed, but the ParentActivity( The ActivityGroup ) is not resumed , and the app show just a null Window with the Title of My App ( “My Application Title” ) .

The Code to launch the Activity A from my ActivityGroup is :

View view = getLocalActivityManager().startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) .getDecorView();
this.setContentView(view);

and i have overrided the method onKeyDown like this in my ActivityGroup :

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        Log.i(TAG, "onKeyDown");
        if(keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0){
            Activity current = getLocalActivityManager().getCurrentActivity();
            Log.i(TAG, current.getIntent().getStringExtra("id"));
            current.finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

but it seems that the method onKeyDown is never called because a i didn’t get the Log “onKeyDown” displayed.

and the logcat display just this :

01-05 11:04:38.012: W/KeyCharacterMap(401): No keyboard for id 0
01-05 11:04:38.012: W/KeyCharacterMap(401): Using default keymap: /system/usr/keychars/qwerty.kcm.bin

what i want is to display the ActivityGroup when my Activity A is Destroyed.

NB : my app level is 4 : *Android 1.6* , so i can’t override the method onBackPressed()

Thank you all for your help

———————————–EDIT —————————————-

I have added the code of my onKeyDown like this on my Activity A :

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    if(keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0){
        ParentActivity parentActivity = (ParentActivity) this.getParent();
        parentActivity.onKeyDown(keyCode, event);
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

And in my ParentActivity , i have :

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0){
            Log.i(TAG, "onKeyDown");
            int len = idOfSubActivities.size();
            String idOfCurrentActivity = idOfSubActivities.get(len-1);
            Activity currentActivity = getLocalActivityManager().getActivity(idOfCurrentActivity);
            currentActivity.finish();
            idOfSubActivities.remove(len - 1);
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

I got the same result , the Activity A is stopped , but it still give me the null window with the title of my app , and it doesn’t display my ActivityGroup (ParentActivity)

  • 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-27T23:27:18+00:00Added an answer on May 27, 2026 at 11:27 pm

    I faced a problem similar to this when I first started experimenting with ActivityGroups. The issue is that you need to place your onKeyDown() in your Activity. However, you need the Activity to have a reference to the ActivityGroup. Then, when you press back, just call your own onBack() in the ActivityGroup.

    (EDIT) Here’s a Sample for you

    Below is the stripped down ActivityGroup code that handles navigation and history in my apps. It has been adjusted on the fly, so there might be an error. Notice a couple of finer points.

    public class MyGroup extends ActivityGroup
    {
    /** Static Reference to this Group. */
        static MyGroup instance;
    /** Keeps Track of the History as a Stack. */
        private ArrayList<View> myActivityHistory;
    
        @Override protected void onCreate(final Bundle savedInstanceState)
        {//Call the Base Implementation
            super.onCreate(savedInstanceState);
    
        // Initialize the Activity History
            myActivityHistory = new ArrayList<View>();
    
        // Build the Intent
            Intent _root = null;
        //Lists the Applications
            _root = new Intent(this, MyActivity.class);
        // Send the Index to the Child Activity
            _root.setAction(Intent.ACTION_VIEW);
        // Forward the Extras, if they are there
        // Start the root Activity within the Group and get its View
            final View _view = getLocalActivityManager().startActivity("App Preferences", _root).getDecorView();
        // Start the History
            addNewLevel(_view);
        }
    
        /**
         * Gets the instance of the {@link ApplicationGroup} that the child Activity
         * belongs to.
         *
         * @param index
         *  The Group that was passed to the child in the {@link android.content.Intent
         *  Intent} via an Extra (int).
         * @return
         *  <b>ApplicationGroup -</b> The group that this child was assigned to.
         */
        static public ApplicationGroup getGroup()
        {   if (instance != null)
                return instance;
        }
    
        /**
         * Allows the Child to replace the {@link ApplicationGroup}'s current
         * {@link android.view.View View} with the specified View. This is
         * intended to be used specifically by the Child.
         *
         * @param withView
         *  The View to use for replacement.
         */
        public void addNewLevel(final View withView)
        {//Adds the old one to history
            myActivityHistory.add(withView);
        // Changes this Groups View to the new View.
            setContentView(withView);
        }
    
        /**
         * Takes the specified {@link android.app.ActivityGroup ActivityGroup} back
         * one step in the History to the previous {@link android.view.View View}.
         */
        public void back()
        {   Log.d("Group", "Back overridden");
            //If there are more than one screen
            if (myActivityHistory.size() > 1)
            {   Log.d("Group", "History called");
            // Remove the most recent View
                myActivityHistory.remove(myActivityHistory.size()-1);
            // Change the View back.
                setContentView(myActivityHistory.get(myActivityHistory.size()-1));
            }
        // Otherwise Exit
            else
            {   Log.d("Group", "Program finished");
                finish();
            }
        }
    
    }
    

    Next is the pertinent code for the Activity:

    public boolean onKeyDown(int keyCode, KeyEvent event)
    {//If back was pressed
        if (keyCode==KeyEvent.KEYCODE_BACK)
        {   MyGroup.getGroup().back();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
    

    Just make sure that you aren’t setting the KeyDownListener to anything funny and it should work fine. 🙂 The changes that I made are because I actually have them in an array of Groups (3 at one time). Essentially, just make the Group a Singleton so you can always have the same instance, and keep an array of your Views so that you have a History. Then reference the History when you click Back or when you add a View.

    Hope this helps,
    FuzzicalLogic

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6

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.