chufengma / android-skills

android 平时需要注意的小技巧,小构思,小想法。
6 stars 2 forks source link

Context.startActivity() 注意事项 #25

Open chufengma opened 8 years ago

chufengma commented 8 years ago
  1. 使用除activity以外的context打开activity的时候,必须带上flag:FLAG_ACTIVITY_NEW_TASK,才能启动成功。比如通过Application的context打开activity。 这是因为,启动activity需要一个依附的task,使用非activity的context是没有task的,只能告诉它去启动一个task。

Note that if this method is being called from outside of an Activity Context, then the Intent must include the FLAG_ACTIVITY_NEW_TASK launch flag. This is because, without being started from an existing Activity, there is no existing task in which to place the new activity and thus it needs to be placed in its own separate task.