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)
I faced a problem similar to this when I first started experimenting with
ActivityGroups. The issue is that you need to place youronKeyDown()in yourActivity. However, you need theActivityto have a reference to theActivityGroup. Then, when you press back, just call your ownonBack()in theActivityGroup.(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.
Next is the pertinent code for the Activity:
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