intent.getAction()返回NULL

Ste*_*ver 8 android android-manifest android-intent

在我的应用程序中,我添加了一个启动画面,我创建了启动活动,并对清单文件进行了适当的更改.但是,当我现在运行我的应用程序时,启动屏幕会显示其分配的时间,然后返回NullPointerException.问题是由于

 intent.getAction()
Run Code Online (Sandbox Code Playgroud)

在我的splash重定向到的类的第241行,intent.getAction()返回null.据我所知,该操作是从指定活动的清单文件中获取的.这是正确的不是吗?如果是这样,有人可以看看这个,看看我是否有什么问题?我没有看错.

 <activity android:name=".Main"
              android:label="@string/app_name">       

    </activity>

   <activity android:name=".SplashActivity" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">

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

            <data android:mimeType="*/*" />
            <category android:name="android.intent.category.OPENABLE" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
Run Code Online (Sandbox Code Playgroud)

__ _ __ _ __ _如果正在检索操作的语句_ __ _ __ _ __ _ ____

 Intent intent = getIntent();

    System.out.println("Intent action is " + intent.getAction());
    if(intent.getAction().equals(Intent.ACTION_GET_CONTENT)) {
        bimg[5].setVisibility(View.GONE);
        mReturnIntent = true;
 } else if (intent.getAction().equals(ACTION_WIDGET)) {
        Log.e("MAIN", "Widget action, string = " + intent.getExtras().getString("folder"));
        mHandler.updateDirectory(mFileMag.getNextDir(intent.getExtras().getString("folder"), true));

    }
}
Run Code Online (Sandbox Code Playgroud)

ada*_*amp 20

该动作是从启动该活动的Intent中获取的.清单intent-filters定义除了直接将该活动指定为目标的意图之外还将匹配哪种意图.

如果您使用以下内容启动活动,则该操作为null是完全正常的:

startActivity(new Intent(this, MyTargetActivity.class));
Run Code Online (Sandbox Code Playgroud)

您没有为Intent指定操作,因此没有.在测试接收到的intent的操作时,反转检查通常很有用:

if (Intent.ACTION_GET_CONTENT.equals(intent.getAction())) {
    // ...
}
Run Code Online (Sandbox Code Playgroud)

避免需要显式空检查,因为常量Intent.ACTION_GET_CONTENT不会为空.

(请注意,即使在这种情况下没有任何操作检查匹配,您的代码仍然必须做一些合理的事情.)

  • `new Intent(Intent.ACTION_GET_CONTENT)`、`myIntent.setAction(Intent.ACTION_GET_CONTENT)`等:) http://developer.android.com/reference/android/content/Intent.html (2认同)
  • 别客气!现在放下启动画面,只需启动到你的应用程序.它更清洁.;) (2认同)