Issue
I am developing an android app. I want my app to have a home button. So I decide to use a clickable ImageView for that, which I am placing in the title bar. Whenever a user clicks on the home image, the app will navigate to the home screen: which I accomplish by having the image dispatch an intent to start the HomeActivity.
My concern is that the whole approach feels like poor design (I may be wrong). Basically all activities follow the HomeActivity. And since I don't normally call finish()
on my activities (so to allow back-button navigation) would I end up in a loop? As in, say a user goes from HomeActivity to FooActivity then to BarActivity then clicks on the home image hence going to HomeActivity. I know I can rely on android to reclaim memory when it needs it. But I don't want my app to tax the system so much.
So how do android designers normally design home
icons/buttons so to avoid this looping problem? Or is android aware that I am returning to HomeActivity and thus may finish the previous instances of the other activities I just walked through?
Solution
Using the App Icon for Navigation for this
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// app icon in action bar clicked; go home
Intent intent = new Intent(this, HomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Answered By - Arun C
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.