对生命周期和日程安排感到困惑

时间:2018-02-26 16:40:18

标签: android

我可能会对调度的工作方式感到有些困惑,我希望有人能够纠正我,或者告诉我,我是对的。

首次启动应用时,系统会根据清单中的指定启动活动Main Activity

(...)

Main Activity启动Secondary Activity然后暂停,而后者则会暂停。

(...)

Secondary Activity到达启动intentservice的最后一条指令,表示服务在另一个线程上启动并自行运行。 Secondary Activity到达终点并停止,Main Activity恢复执行。

我不考虑任何外部操作系统干预。

我错过了什么吗?

编辑:Secondary Activity代码

public class SecondaryActivity extends Activity {

        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            Intent mis = new Intent(this,MyIntentService.class);
            this.startService(mis);
            finish();
        }
    }

1 个答案:

答案 0 :(得分:1)

Can you please a give a more detailed information about how the SecondaryActivity ends and stops are you calling finish() on it after its execution is done or calling the MainActivity explicitly? Activity do maintain a stack when you call an activity from an intent that activity is added to stack and unless and untill you do not finish the activity it wont get to the FirstActivity in your case MainActivity