Java 飞溅屏幕和意图

Java 飞溅屏幕和意图,java,android,android-intent,splash-screen,Java,Android,Android Intent,Splash Screen,我正在开发这个android应用程序,它接收来自图库的数据(在我的例子中是图像)并显示它。我还必须为我的应用程序创建一个SplashScreen。但当我这么做的时候,我的意图就变得无效了 舱单代码: 主要活动 我不确定这是否能解决你的问题,但你可以试试 而不是: Intent i = new Intent(SplashScreen.this, AlertExampleActivity.class); startActivity(i); // clo

我正在开发这个android应用程序,它接收来自图库的数据(在我的例子中是图像)并显示它。我还必须为我的应用程序创建一个
SplashScreen
。但当我这么做的时候,我的意图就变得无效了

舱单代码:

主要活动


我不确定这是否能解决你的问题,但你可以试试

而不是:

Intent i = new Intent(SplashScreen.this, AlertExampleActivity.class);
            startActivity(i);
            // close this activity
            finish();
试试这个:

startActivity(new Intent(SplashScreen.this, AlertExampleActivity.class));
finish();

我不确定这是否能解决你的问题,但你可以试试

而不是:

Intent i = new Intent(SplashScreen.this, AlertExampleActivity.class);
            startActivity(i);
            // close this activity
            finish();
试试这个:

startActivity(new Intent(SplashScreen.this, AlertExampleActivity.class));
finish();

您没有在意图中添加任何额外数据。所以它通常是空的。只需在
SplashScreen.java
上的
Intent
(i)中添加必要的数据即可。前-

i.setAction("action"); 
i.setType("type");
i.putExtra("key", "value");

您没有在意图中添加任何额外数据。所以它通常是空的。只需在
SplashScreen.java
上的
Intent
(i)中添加必要的数据即可。前-

i.setAction("action"); 
i.setType("type");
i.putExtra("key", "value");

我更改了清单文件,因为我希望即使在外部调用splashscreen时也能显示它

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".AlertExampleActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>



    </activity>

    <activity android:name=".SplashScreen">
        <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.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="image/*" />
            <data android:mimeType="text/*" />
        </intent-filter>

    </activity>

</application>

我没有在主活动中更改任何内容,但现在我不再收到图像。。。我是Android新手,所以我非常感谢您的解释

我更改了清单文件,因为我希望即使在外部调用splashscreen时也能显示它

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".AlertExampleActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>



    </activity>

    <activity android:name=".SplashScreen">
        <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.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="image/*" />
            <data android:mimeType="text/*" />
        </intent-filter>

    </activity>

</application>


我没有在主活动中更改任何内容,但现在我不再收到图像。。。我是Android新手,所以我非常感谢您的解释

你能写细节吗?你的意图何时失效?在哪个活动中?我有一个错误:由以下原因引起:java.lang.NullPointerException:尝试调用虚拟方法“boolean java.lang.String.equals(java.lang.Object)”'在com.example.xkbc1923.myapplication.AlertExampleActivity.onCreate(AlertExampleActivity.java:48)上的空对象引用上,您没有向意图添加任何额外数据。所以它通常是空的。只需在SplashScreen.java的intent(i)中添加必要的数据。Ex-i.putExtra(“键”、“值”);i、 设定动作(“动作”);i、 setType(“类型”);你能写细节吗?你的意图何时失效?在哪个活动中?我有一个错误:由以下原因引起:java.lang.NullPointerException:尝试调用虚拟方法“boolean java.lang.String.equals(java.lang.Object)”'在com.example.xkbc1923.myapplication.AlertExampleActivity.onCreate(AlertExampleActivity.java:48)上的空对象引用上,您没有向意图添加任何额外数据。所以它通常是空的。只需在SplashScreen.java的intent(i)中添加必要的数据。Ex-i.putExtra(“键”、“值”);i、 设定动作(“动作”);i、 setType(“类型”);我试过:Intent I=newintent(SplashScreen.this、AlertExampleActivity.class);i、 设置动作(意图、动作和主);i、 setType(“image/*”);字符串[]mimetypes={“image/*”,“video/*”};i、 putExtra(Intent.EXTRA\u MIME\u类型、mimetypes);星触觉(i);但问题是,现在我再也没有收到图像了。请分享你修改过的代码。可能是ImageView对此不可见-picView.setVisibility(View.GONE);我在下面分享了您在AlertExampleActivity上使用的picView.setVisibility(View.GONE)。这可能是您要显示图像的图像视图。设置为picView.setVisibility(View.VISIBLE)。我试过:Intent I=newintent(SplashScreen.this,AlertExampleActivity.class);i、 设置动作(意图、动作和主);i、 setType(“image/*”);字符串[]mimetypes={“image/*”,“video/*”};i、 putExtra(Intent.EXTRA\u MIME\u类型、mimetypes);星触觉(i);但问题是,现在我再也没有收到图像了。请分享你修改过的代码。可能是ImageView对此不可见-picView.setVisibility(View.GONE);我在下面分享了您在AlertExampleActivity上使用的picView.setVisibility(View.GONE)。这可能是您要显示图像的图像视图。设置为picView.setVisibility(View.VISIBLE)。你能给我看一下你不能从MainActivity收到的图像/对象吗?你说的是-String[]mimetypes={“image/*”,“video/*”};i、 putExtra(Intent.EXTRA\u MIME\u类型、mimetypes);问题是,由于我将动作设置为“动作\发送”,即使我直接启动应用程序,它也会给我发送,而它应该是主活动。你能给我看一下不能从主活动接收的图像/对象吗?你说的是-String[]mimetypes={“image/*”,“video/*”};i、 putExtra(Intent.EXTRA\u MIME\u类型、mimetypes);问题是,由于我将动作设置为动作发送,即使当我直接启动应用程序时,它也会给我发送,而它应该是主。