Android 中设置Activity永不过期,销毁

Android QQ交流群:826464336

保持Activity永不销毁……

public class MainActivity extends Activity {
private static final String tag = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.e(tag, "onCreate method is onCreate");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
protected void onDestroy() {
Log.e(tag, "onCreate method is onDestroy");
super.onDestroy();
}
@Override
public void finish() {
/**
* 记住不要执行此句 super.finish(); 因为这是父类已经实现了改方法
* 设置该activity永不过期,即不执行onDestroy()

*/
moveTaskToBack(true);
}
}

 

 

 

你可能感兴趣的:(Android 中设置Activity永不过期,销毁)