0

我有 3 项活动
-scelta
-checkin
-instarghe

表格 scelta 和 checkin 我可以去 instarghe。我希望当我从签入进入 instarghe 时,如果我使用后退按钮,签入活动将重新执行。
示例:
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
        }
    });
};

但是当我尝试时,应用程序崩溃了。这是日志猫:

java.lang.RuntimeException:无法恢复活动 {com.homelinux.agnese/com.homelinux.agnese.entrata}:android.app.SuperNotCalledException:活动 {com.homelinux.agnese/com.homelinux.agnese.entrata} 没有调用 super.onRestart() 原因:android.app.SuperNotCalledException: Activity {com.homelinux.agnese/com.homelinux.agnese.entrata} 没有调用 super.onRestart()

4

2 回答 2

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
        }
    });
};
于 2012-06-30T13:59:31.113 回答
0

在签入中使用onRestart()并在此处使用重新执行逻辑。可能这会解决你的问题。

onRestart()在覆盖的版本中调用超类onRestart()

于 2012-06-30T13:18:51.613 回答