当在设置的开发人员选项进度对话框中选择“不保留活动”时,不会关闭。实际上,我正在显示 Progerss 栏,用于初始化应用程序,当我从 Activity A 到 Activity B 然后来到 Activity A 时,初始化完成后进度栏不会消失。下面是我的代码,
第一个活动
package com.example.donotkeepactivitiesalive;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
public static final int MESSAGE_PROGRESS_BAR_INITIALIZING = 1;
private Dialog m_cObjDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
System.out.println(getClass().getName() + "before InitializeEnvironment >>>>>>");
new InitializeEnvironment().execute();
System.out.println(getClass().getName() + "after InitializeEnvironment >>>>>>");
Button lb = (Button) findViewById(R.id.button1);
lb.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent lIntent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(lIntent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
protected Dialog onCreateDialog(int id) {
m_cObjDialog = new ProgressDialog(this);
m_cObjDialog.setTitle("Initializing");
((ProgressDialog) m_cObjDialog).setMessage("Initializing the Application");
m_cObjDialog.setCancelable(false);
return m_cObjDialog;
}
class InitializeEnvironment extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
System.out.println(getClass().getName() + "onPreExecute >>>>>>");
super.onPreExecute();
showDialog(MESSAGE_PROGRESS_BAR_INITIALIZING);
}
@Override
protected String doInBackground(String... aurl) {
System.out.println(getClass().getName() + " doInBackground >>>>>>");
return null;
}
@Override
protected void onPostExecute(String unused) {
dismissDialog(MESSAGE_PROGRESS_BAR_INITIALIZING);
System.out.println(getClass().getName() + " onPostExecute >>>>>>");
}
}
}
第二次活动
package com.example.donotkeepactivitiesalive;
import android.app.Activity;
import android.os.Bundle;
public class SecondActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
即使启用了“不保留活动”,是否有任何方法可以跟踪此问题并正常工作