I built home button on custom titlebar (use picture to button).
My Problem is every time to click this button. It will go to main.
When stay in main page and click the button. It will to main page again and again.
How I do??
I want it not go to main when stay main or Can’t click this button in main page.
Are you understand?
Please help me
Thank you
public class CustomTitleBar extends Activity {
protected ImageButton toHome;
protected TextView title;
protected ImageView icon;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
toHome = (ImageButton) findViewById(R.id.header);
title = (TextView) findViewById(R.id.title);
icon = (ImageView) findViewById(R.id.icon);
ProgressBar titleProgressBar = (ProgressBar) findViewById(R.id.loadProgress);
titleProgressBar.setVisibility(ProgressBar.GONE);
/* -- Button to HOME -- */
toHome.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent goHome = new Intent(Intent.ACTION_MAIN);
goHome.setClass(CustomTitleBar.this, MainActivity.class);
startActivity(goHome);
finish();
}
});
}
}
have people tell me to use finish(); but it can’t fix my problem.
from example : main > page1 > (click home) > main > page2 > (click home) > main
when click back button on mobile
cycle is : main > page2 > main > page1 > main > out of app.
when click back button on mobile after I use finish();
cycle is : main > main > main > out of app.
Add flag Intent.FLAG_ACTIVITY_CLEAR_TOP when you navigate from sub page to home.
Here’s my example code: