当我以这种方式宣布我的主要活动时:
<activity android:name=".MyActivity"
android:configChanges="orientation|keyboardHidden"
android:windowSoftInputMode="stateHidden"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="com.package.name.MyActivity"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
No Activity found to handle Intent { act=com.package.name.MyActivity flg=0x24000000 }
然后当我使用此代码时出现错误:
Intent intent = new Intent("com.package.name.MyActivity");
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
如果不使用Intent i = new Intent(this, MyActivity.class);
,我该如何在action
for的帮助下做到这一点<intent-filter>
没有帮助:
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="com.package.name.VIEW"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
代码:
Intent intent = new Intent("com.package.name.VIEW");
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);