我有3个活动
-scelta
-checkin
-instarghe
形成scelta并签入我可以去实验。
我希望当我从签入进入实验时,如果我使用后退按钮,则签到活动将重新执行。
例如:
checkin - > instarghe - >后退按钮 - >我第二次执行checkin
scelta - > instarghe - >后退按钮 - >通常返回scelta
我该怎么办?
我写这段代码:
protected void onRestart(){
//popolamento dello spinnero
String risposta=postTarghe();
Spinner spinner = (Spinner) findViewById(R.id.spnTarghe);
final String targhe[]=risposta.split("/");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this,
android.R.layout.simple_spinner_item,
targhe
);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View v, int position,long id) {
sTarga=targhe[position];
Log.d(TAG,"questa è la posizione selezionata: "+position);
Log.d(TAG,"questa è la targa: "+sTarga);
}
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
});
};
但是当我尝试时,应用程序崩溃了。 这是logcat:
java.lang.RuntimeException:无法恢复活动{com.homelinux.agnese / com.homelinux.agnese.entrata}:android.app.SuperNotCalledException:Activity {com.homelinux.agnese / com.homelinux.agnese.entrata没有调用super.onRestart() 引起:android.app.SuperNotCalledException:Activity {com.homelinux.agnese / com.homelinux.agnese.entrata}没有调用super.onRestart()
答案 0 :(得分:1)
首先:请在您的问题中发布您的代码,而不是作为答案!
第二:
protected void onRestart(){
/****************
* You forgot following line
****************/
super.onRestart();
/***************/
//popolamento dello spinnero
String risposta=postTarghe();
Spinner spinner = (Spinner) findViewById(R.id.spnTarghe);
final String targhe[]=risposta.split("/");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this,
android.R.layout.simple_spinner_item,
targhe
);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View v, int position,long id) {
sTarga=targhe[position];
Log.d(TAG,"questa è la posizione selezionata: "+position);
Log.d(TAG,"questa è la targa: "+sTarga);
}
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
});
};
答案 1 :(得分:0)
在checkin&amp;中使用onRestart()
在这里使用重新执行逻辑。这可能会解决你的问题。
在被覆盖的onRestart()
onRestart()