我有 2 个活动。在我的第一个中,我有一个按钮,当我单击它时,它会启动第二个活动。但是当我回到我的第一个并且我第二次单击我的按钮时,我的第二个活动开始但我必须返回两次才能回到我的第一个活动。
如果再次单击一次,则必须返回 3 次...
请帮帮我。并提前谢谢你:)
这是我的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this._that = this;
_progressDialog = new ProgressDialog(this);
EditText editText = (EditText) findViewById(R.id.MainActivityEditText);
editText.setText("T_F81D4FA3F8");
Button button = (Button) findViewById(R.id.MainActivityButton);
button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if(v.getId() == R.id.MainActivityButton ) {
Log.w("MainActivity", "onClick");
_progressDialog.setMessage("Chargement en cours");
_progressDialog.show();
new Thread(new Runnable() {
public void run() {
EditText editText = (EditText) findViewById(R.id.MainActivityEditText);
String s = editText.getText().toString().replace(" ", "");
Log.i("EditText", s);
ID_APPLICATION = s;
//if (! Datas.getInstance().isUpdateDatas())
WebService.getInstance().datas(_that);
LocalBroadcastManager.getInstance(_that).registerReceiver(datasUpdateFail, new IntentFilter("datas-update-fail"));
LocalBroadcastManager.getInstance(_that).registerReceiver(datasUpdate, new IntentFilter("datas-update"));
}
}).start();
}
}
BroadcastReceiver datasUpdate = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
myStartActivity("ACCUEIL");
_progressDialog.dismiss();
}
};
BroadcastReceiver datasUpdateFail = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(MainActivity.this, "Erreur : Veuillez verifier votre identifiant ou votre connexion", Toast.LENGTH_SHORT).show();
_progressDialog.dismiss();
}
};
public void myStartActivity(String page){
Intent intent = new Intent(this, PageActivity.class);
Bundle bundle = new Bundle();
bundle.putString("page", page);
intent.putExtras(bundle);
this.startActivity(intent);
}