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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:13:46+00:00 2026-05-24T17:13:46+00:00

Basically I’m using ActivityGroup in my application. I have this situation: I have Tabhost

  • 0

Basically I’m using ActivityGroup in my application. I have this situation:

I have Tabhost with activity A.

Activity A creates childActivity B.

A  --->  B

startChildActivity("CollectionList", new Intent(this,MyCollectionList.class));

Activity B creates 3 childactivities C, D.

B  ---> C (childActivity of B)
startChildActivity("Recommended", new Intent(MyCollectionList.this,Recommended.class));


B  ---> D (childActivity of B)
startChildActivity("ExpectSoon", new Intent(MyCollectionList.this,ExpectSoon.class));

B creates another childActivity too, name it E.

B  ---> E
Intent previewMessage = new Intent(getParent(), MyCollectionId.class);
TabGroupActivity parentActivity = (TabGroupActivity)getParent();
parentActivity.startChildActivity("MyCollectionId", previewMessage);

So basically Activity C and D can start activity E too, with :

            Intent previewMessage = new Intent(getParent(), MyCollectionId.class);
            TabGroupActivity parentActivity = (TabGroupActivity)getParent();
            parentActivity.startChildActivity("MyCollectionId", previewMessage);

I had Override the onBackPressed method so I can control the back button.It looks like this :

    private ArrayList<String> mIdList;

@Override
  public void  onBackPressed  () {
      int length = mIdList.size();
      if ( length >=1) {
          Activity current = getLocalActivityManager().getActivity(mIdList.get(length-1));
          current.finish();
      }
  }

So my problem is that when I’m in activity E and press the back button my application close.And the other problem that I have is with the alert dialog in activity E.

Button deactivate = (Button) findViewById(R.id.deactivate);
        deactivate.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                new AlertDialog.Builder( getParent() )
                .setTitle( "Warning" )
                .setMessage( "The collection will be removed completely from the device.You can reactivate it later again.This operation requires internet connection." )
                .setPositiveButton( "Go ahead", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        Log.d("AlertDialog", "Positive");
                    }
                })
                .setNegativeButton( "Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        Log.d("AlertDialog","Negative");
                    }
                })
                .show();    

            }

    });

When I start Activity E from A, when I click the button,which will show the alert dialog,everything is ok.But when I start activity E from C or D it throws me that exception :

08-15 15:48:22.819: ERROR/AndroidRuntime(32440): FATAL EXCEPTION: main
08-15 15:48:22.819: ERROR/AndroidRuntime(32440): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@4630ea20 is not valid; is your activity running?
08-15 15:48:22.819: ERROR/AndroidRuntime(32440):     at android.view.ViewRoot.setView(ViewRoot.java:509)
08-15 15:48:22.819: ERROR/AndroidRuntime(32440):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
08-15 15:48:22.819: ERROR/AndroidRuntime(32440):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-15 15:48:22.819: ERROR/AndroidRuntime(32440):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
08-15 15:48:22.819: ERROR/AndroidRuntime(32440):     at android.app.Dialog.show(Dialog.java:241)
08-15 15:48:22.819: ERROR/AndroidRuntime(32440):     at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
08-15 15:48:22.819: ERROR/AndroidRuntime(32440):     at com.stampii.stampii.mystampii.MyCollectionId$4.onClick(MyCollectionId.java:75)
08-15 15:48:22.819: ERROR/AndroidRuntime(32440):     at android.view.View.performClick(View.java:2408)
08-15 15:48:22.819: ERROR/AndroidRuntime(32440):     at android.view.View$PerformClick.run(View.java:8817)
08-15 15:48:22.819: ERROR/AndroidRuntime(32440):     at android.os.Handler.handleCallback(Handler.java:587)
08-15 15:48:22.819: ERROR/AndroidRuntime(32440):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-15 15:48:22.819: ERROR/AndroidRuntime(32440):     at android.os.Looper.loop(Looper.java:144)
08-15 15:48:22.819: ERROR/AndroidRuntime(32440):     at android.app.ActivityThread.main(ActivityThread.java:4937)
08-15 15:48:22.819: ERROR/AndroidRuntime(32440):     at java.lang.reflect.Method.invokeNative(Native Method)
08-15 15:48:22.819: ERROR/AndroidRuntime(32440):     at java.lang.reflect.Method.invoke(Method.java:521)
08-15 15:48:22.819: ERROR/AndroidRuntime(32440):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-15 15:48:22.819: ERROR/AndroidRuntime(32440):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-15 15:48:22.819: ERROR/AndroidRuntime(32440):     at dalvik.system.NativeStart.main(Native Method)

EDIT:

My startChildActivity looks like this :

public void startChildActivity(String Id, Intent intent) {     
      Window window = getLocalActivityManager().startActivity(Id,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
      if (window != null) {
          mIdList.add(Id);
          setContentView(window.getDecorView()); 
      } 

}

latest LogCat,while using Recommended.parentActivity in ActivityE :

        new AlertDialog.Builder( Recommended.parentActivity )


08-15 16:33:53.509: ERROR/AndroidRuntime(1967): FATAL EXCEPTION: main
08-15 16:33:53.509: ERROR/AndroidRuntime(1967): java.lang.NullPointerException
08-15 16:33:53.509: ERROR/AndroidRuntime(1967):     at com.android.internal.app.AlertController$AlertParams.<init>(AlertController.java:743)
08-15 16:33:53.509: ERROR/AndroidRuntime(1967):     at android.app.AlertDialog$Builder.<init>(AlertDialog.java:273)
08-15 16:33:53.509: ERROR/AndroidRuntime(1967):     at com.stampii.stampii.mystampii.MyCollectionId$4.onClick(MyCollectionId.java:62)
08-15 16:33:53.509: ERROR/AndroidRuntime(1967):     at android.view.View.performClick(View.java:2408)
08-15 16:33:53.509: ERROR/AndroidRuntime(1967):     at android.view.View$PerformClick.run(View.java:8817)
08-15 16:33:53.509: ERROR/AndroidRuntime(1967):     at android.os.Handler.handleCallback(Handler.java:587)
08-15 16:33:53.509: ERROR/AndroidRuntime(1967):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-15 16:33:53.509: ERROR/AndroidRuntime(1967):     at android.os.Looper.loop(Looper.java:144)
08-15 16:33:53.509: ERROR/AndroidRuntime(1967):     at android.app.ActivityThread.main(ActivityThread.java:4937)
08-15 16:33:53.509: ERROR/AndroidRuntime(1967):     at java.lang.reflect.Method.invokeNative(Native Method)
08-15 16:33:53.509: ERROR/AndroidRuntime(1967):     at java.lang.reflect.Method.invoke(Method.java:521)
08-15 16:33:53.509: ERROR/AndroidRuntime(1967):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-15 16:33:53.509: ERROR/AndroidRuntime(1967):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-15 16:33:53.509: ERROR/AndroidRuntime(1967):     at dalvik.system.NativeStart.main(Native Method)
  • 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-24T17:13:47+00:00Added an answer on May 24, 2026 at 5:13 pm

    you can do onething
    in ActivityA.java

    public static Activity parentActivity;
    
    onCreate()
    {
         parentActivity=this;
    } 
    // start your child activity ie(E)
    

    ActivityE.java

    Button deactivate = (Button) findViewById(R.id.deactivate);
            deactivate.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    new AlertDialog.Builder( ActivityA.parentActivity.this )
                    .setTitle( "Warning" )
                    .setMessage( "The collection will be removed completely from the device.You can reactivate it later again.This operation requires internet connection." )
                    .setPositiveButton( "Go ahead", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            Log.d("AlertDialog", "Positive");
                        }
                    })
                    .setNegativeButton( "Cancel", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            Log.d("AlertDialog","Negative");
                        }
                    })
                    .show();    
    
                }
    
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically what I have here is a button that adds a new list item
Basically I have a loop incrementing i, and I want to do this: var
Basically I have this server app I built in vc#, and for some reason
Basically what I want to do it this: a pdb file contains a location
Basically, something better than this: <input type=file name=myfile size=50> First of all, the browse
Basically I have some code to check a specific directory to see if an
Basically I want to know how to set center alignment for a cell using
Basically I have an asp.net website with login and search pages. Currently, I have
Basically I have a drop down list which is populated with text and values
basically i need to write a query for mysql, but i have no experience

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.