問題:Actionbarsherlock後退按鈕和智能手機的後退按鈕
我有,我想,當我無論從智能手機和動作條上的第二活動按後退按鈕回調的主要活動。但它總是崩潰,它只是當我把完成();在主要活動中,但如果我這樣做,那麼智能手機的後退按鈕無法正常工作。
MainActivity:
public class Principal extends SherlockActivity {
public static int THEME = R.style.Theme_Sherlock;
private Button entrar;
private Button cadastrar;
@Override
protected void onCreate(Bundle savedInstanceState) {
//setTheme(Principal.THEME); //Used for theme switching in samples
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
entrar = (Button)findViewById(R.id.entrar);
entrar.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
startActivity(new Intent(Principal.this,LoginActivity.class));
finish();
}
});
cadastrar = (Button)findViewById(R.id.cadastrar_home);
cadastrar.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent(Principal.this, RegisterActivity.class);
startActivity(intent);
//finish();
}
});
}
SecondActicity:
public class RegisterActivity extends SherlockActivity{
protected void onCreate(Bundle savedInstanceState) {
setTheme(Principal.THEME); //Used for theme switching in samples
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId())
{
case android.R.id.home:
// Do whatever you want, e.g. finish()
Intent intent = new Intent(this, Principal.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
break;
}
return true;
}
}
已經嘗試過很多方法,沒有工作,只有完成();
謝謝,還有答案。 – Marckaraujo