在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);