I have a TabActivity that has three tabs. The fist tab is the problem. The first tab loads an ActivityGroup. OnCreate it loads a default content view. Later on a certain event, we add a different content view. This works fine, but my problem is when someone presses the back button on the phone after the second content view gets loaded. It takes them to the last Activity instead of taking them to the first content view that was added in the ActivityGroup. How can I redirect the back button to call a method in my ActivityGroup?
I am constructing it this way that I might have multiple views(Activities) within one tab. Any ideas on how to redirect the back button event to my own method? That would be easy and nice.
In case the code is helpful:
public class LiveTabGroup extends ActivityGroup implements MoveToScreenNotification.handler
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
EventBus.subscribe(MoveToScreenNotification.class, this);
View view = getLocalActivityManager().startActivity("CameraListView", new Intent(this,CameraListView.class).
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
this.setContentView(view);
}
@Override
public void onMoveToScreenNotification(MoveToScreenNotification notif)
{
if (notif.newScreen == MoveToScreenNotification.SCREEN_MOVIEPLAYER_LIVE)
{
SugarLoafSingleton.currentCamera.url = notif.videoURL;
// Throw UI management on main thread
runOnUiThread(new Runnable(){
public void run()
{
StartPlayer();
}
});
}
}
public void StartPlayer()
{
View view = getLocalActivityManager().startActivity("VideoPlayer", new Intent(this,VideoPlayerView.class).
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
this.addContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT));
}
}
I had to override the Back button myself. See below for code that does this for you. Basically, this overrides the default implementation of onKeyDown that is in the Android Activity class. The keycode for the back button is KeyEvent.KEYCODE_BACK and this code catches that. For anything else, it will just run the default handler: