简体   繁体   English

找不到活动来处理默认活动的Intent

[英]No Activity found to handle Intent for Default Activity

I get error No Activity found to handle Intent when I try to start Default Activity from another Activity using 当我尝试从另一个Activity启动默认活动时,我收到错误No Activity found to handle Intent

Intent start = new Intent("com.name.name.MainActivity");
startActivity(start);
finish();

I guess this is because in AndroidManifest for Default Activity I have android.intent.action.MAIN 我想这是因为在AndroidManifest for Default Activity中我有android.intent.action.MAIN

  <intent-filter>
              <action android:name="android.intent.action.MAIN" />

              <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>

Is there a way to start Default Activity from another Activity when Default Activity is finished before? 有没有办法在默认活动完成之前从另一个Activity启动默认活动?

You are trying to start the activity using the action name.. 您正尝试使用操作名称启动活动。

Note : startActivity() always adds CATEGORY_DEFAULT to an Intent if there is no other category specified(Here you have no category specified in your internt so its default). 注意 :如果没有指定其他类别,则startActivity()始终将CATEGORY_DEFAULT添加到Intent (此处您没有在internt中指定类别,因此它的默认值)。

Hence, an <intent-filter> for an <activity> always needs a <category> , whether DEFAULT or something else (here it needs default that's why error says No Activity found to handle Intent for Default Activity ) 因此, <activity><intent-filter>总是需要<category> ,无论是DEFAULT还是其他东西(这里需要默认值,这就是为什么错误说没有找到活动来处理默认活动的Intent

The LAUNCHER category says that this entry point should be listed in the application launcher. LAUNCHER类别表示此入口点应列在应用程序启动器中。

The DEFAULT category is required for the Context.startActivity() method to resolve your activity when its component name is not explicitly specified. Context.startActivity()方法需要DEFAULT类别,以便在未明确指定其组件名称时解析您的活动。

Try to specify two intent filters: 尝试指定两个intent过滤器:

<activity android:name=".MyActivity"
          android:configChanges="orientation|keyboardHidden"
          android:windowSoftInputMode="stateHidden"
          android:screenOrientation="portrait">
    <intent-filter>
          <action android:name="android.intent.action.MAIN"/>
          <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter>
          <action android:name="com.name.name.MainActivity"/>
          <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>

Then you can start the activity using the action name: 然后,您可以使用操作名称启动活动:

Intent intent = new Intent("com.name.name.MainActivity");
startActivity(intent);

or simply you can go with the class name: 或者只是你可以使用类名:

Intent intent = new Intent(context, MainActivity.class);
startActivity(intent);

Intent i = new Intent(otheractivity.this, MainActivity.class); Intent i = new Intent(otheractivity.this,MainActivity.class); startActivity(i); startActivity(ⅰ);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM