如果FirstActivity
是任务的根,并且它自己完成并启动,SecondActivity
那么立即调用将返回,因为完成是异步发生的,因此还没有完成。等待一秒钟,然后调用返回 true。isTaskRoot()
SecondActivity
false
FirstActivity
isTaskRoot()
public class FirstActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
finish();
startActivity(new Intent(this, SecondActivity.class));
}
}
public class SecondActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
protected void onResume() {
super.onResume();
((TextView)findViewById(R.id.tv1))
.setText("isTaskRoot() in onResume(): " + isTaskRoot());
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
((TextView)findViewById(R.id.tv2))
.setText("isTaskRoot() after 1s: " + isTaskRoot());
}
}, 1000);
}
}
有没有办法...
(最佳)找出活动最终是否会成为任务根,或者,
(总比没有好)一旦任务处于“最终”状态,就会得到某种通知/回调,从而
isTaskRoot()
返回“真相”?