Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Childactivity getParent question?
    primarykey
    data
    text
    <p>Basically I'm using ActivityGroup in my application. I have this situation:</p> <p>I have Tabhost with activity A.</p> <p>Activity A creates childActivity B.</p> <pre><code>A ---&gt; B startChildActivity("CollectionList", new Intent(this,MyCollectionList.class)); </code></pre> <p>Activity B creates 3 childactivities C, D.</p> <pre><code>B ---&gt; C (childActivity of B) startChildActivity("Recommended", new Intent(MyCollectionList.this,Recommended.class)); B ---&gt; D (childActivity of B) startChildActivity("ExpectSoon", new Intent(MyCollectionList.this,ExpectSoon.class)); </code></pre> <p>B creates another childActivity too, name it E.</p> <pre><code>B ---&gt; E Intent previewMessage = new Intent(getParent(), MyCollectionId.class); TabGroupActivity parentActivity = (TabGroupActivity)getParent(); parentActivity.startChildActivity("MyCollectionId", previewMessage); </code></pre> <p>So basically Activity C and D can start activity E too, with : </p> <pre><code> Intent previewMessage = new Intent(getParent(), MyCollectionId.class); TabGroupActivity parentActivity = (TabGroupActivity)getParent(); parentActivity.startChildActivity("MyCollectionId", previewMessage); </code></pre> <p>I had Override the onBackPressed method so I can control the back button.It looks like this :</p> <pre><code> private ArrayList&lt;String&gt; mIdList; @Override public void onBackPressed () { int length = mIdList.size(); if ( length &gt;=1) { Activity current = getLocalActivityManager().getActivity(mIdList.get(length-1)); current.finish(); } } </code></pre> <p>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.</p> <pre><code>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(); } }); </code></pre> <p>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 :</p> <pre><code>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) </code></pre> <p><strong>EDIT:</strong></p> <p>My startChildActivity looks like this :</p> <pre><code>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()); } </code></pre> <p>}</p> <p>latest LogCat,while using Recommended.parentActivity in ActivityE :</p> <pre><code> 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.&lt;init&gt;(AlertController.java:743) 08-15 16:33:53.509: ERROR/AndroidRuntime(1967): at android.app.AlertDialog$Builder.&lt;init&gt;(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) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload