在Activity中可以直接使用Intent启动另一个Activity

显式Intent intent = new Intent(context, activity.class)

隐式 Intent intent = new Intent(“com.aa.www.act”);

startActivity(intent);

 

如果从Service中用同样方法启动Activity 的话,会报错:

android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAGACTIVITYNEWTASK flag. Is this really what you want?

 

需要设置 intent.setFlags(Intent.FLAGACTIVITYNEWTASK); 再开启activity 代码如下 :

Intent intent = new Intent("hahaha.hahaha");

intent.setFlags(Intent.FLAGACTIVITYNEW_TASK);

startActivity(intent);

 

相关文章:

  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2021-07-18
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-20
  • 2021-07-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
  • 2022-12-23
相关资源
相似解决方案