protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG,"OnCreate()");
setContentView(R.layout.activity_main);
mToolbar = findViewById(R.id.my_toolbar);
mTextview = findViewById(R.id.title);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.fragment, new OneFragment());
//ft.commit();
ft.addToBackStack("frag");
ft.commitAllowingStateLoss();
}
}, 5000);
}
最小化我的android应用后,它会自动打开。请帮助我解决此问题
答案 0 :(得分:0)
管理处理程序的正确方法是, 在您的活动中添加以下代码,
private void initTasks() {
handler = new Handler();
runnable = new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}
};
handler.postDelayed(runnable, 5000);
}
@Override
protected void onResume() {
super.onResume();
initTasks();
}
然后在最小化后停止打开您的应用程序,
@Override
protected void onStop() {
super.onStop();
handler.removeCallbacks(null);
}
这将完成您的工作。希望对您有帮助。