startActivity是什么意思

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/01 14:15:02
startActivity是什么意思

startActivity是什么意思
startActivity是什么意思

startActivity是什么意思
是错的吧

startActivity有2种用法
1.显示调用。通过指明ComponentName,显示调用Activity,若
Intent intent = new Intent(CustomerService.this, DetailInfo.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext....

全部展开

startActivity有2种用法
1.显示调用。通过指明ComponentName,显示调用Activity,若
Intent intent = new Intent(CustomerService.this, DetailInfo.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
这种用法需要注意的是在AndroidManifest.xml声明一下Activity,
否则将报throws ActivityNotFoundException if there was no Activity found to run the given Inten
android:launchMode="singleTask"
android:exported="true">





2.隐式调用,只需要指明ACTION就可以了,若
Intent intent = new Intent("com.android.customerservice.ACTION"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
这种用法在AndroidManifest.xml声明Activity需要在intent-filter中添加该ACTION
android:launchMode="singleTask" android:exported="true">









需要注意的是,自定义的ACTION不能加在android.intent.action.MAIN所在的intent-filter中,必须添加在一个新的intent-filter中,同时必须设置category android:name="android.intent.category.DEFAULT,
否则将报throws ActivityNotFoundException if there was no Activity found to run the given Inten

收起

时启动意图的一个方法