Issue
I have Main Activity. That has 4 tabs (TabHost
). I have overridden onBackPress()
in MainActvity, as well as all four activities. This button show user a dialog box and for conformation of Exit
When app start. It show first tab. Then if I press back it works fine.
But if I go for next 3 tab and then press back, the app stop. OnDestroy()
of Main is called. But there is not dialogue for the user.Even noting is print in log cat. That I have written in onBackPressed()
method From and of 5 activities including MainActivity
.
I have also try onKeyDown()
for back key, but the result is same. Why is that the case?
Solution
I come to know it was difficult to open new activity inside the previous tabs when I am using TabHost. I google it and found GroupActivity is the best solution for this problem. GroupActvity Example But GroupActivity have the same problem when open new activity in the previous tab. the back button not work properly for new activity. After search I found that was due to the focus was alwasys on parent activity. I have to make
setFocusable(true); requestFocus();
on my new activity component to gain focus.
I am now using GroupActivity for customizing Tabbar and activities.As I ma also maintaining stack of activity ids in parent activity so that I can pop out the recent activity when user press back button.
else if you are NOT going to implement Activity focus then you should maintain stack in parent and when press the back button it will initiate parent onBackPressed(); and you can call the child onBackPressed() functionality as discussed in the link.
onBackPressed() not working inside ActivityGroup
Answered By - Arslan Anwar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.