<activityandroid:name=".FirstActivity"android:exported="true"android:label="This is FirstActivity"android:launchMode="singleTop"><intent-filter><actionandroid:name="android.intent.action.MAIN"/><categoryandroid:name="android.intent.category.LAUNCHER"/></intent-filter></activity>
overridefunonCreate(savedInstanceState: Bundle?){super.onCreate(savedInstanceState)//在onCreate方法中打印返回栈的id
Log.d("FirstActivity","This is $taskId")setContentView(R.layout.first_layout)//启动ThirdActivityval intent =Intent(this, SecondActivity::class.java)startActivity(intent)}}
修改SecondActivity中的代码
overridefunonCreate(savedInstanceState: Bundle?){super.onCreate(savedInstanceState)
Log.d("SecondActivity","Task id is $taskId")setContentView(R.layout.second_layout)
button2.setOnClickListener{val intent =Intent(this, ThirdActivity::class.java)startActivity(intent)}}
修改ThirdActivity中的代码
overridefunonCreate(savedInstanceState: Bundle?){super.onCreate(savedInstanceState)
Log.d("ThirdActivity","Task id is $taskId")setContentView(R.layout.third_layout)}