我想在我的应用中添加一个启动画面活动。
我正在使用Android Studio 2.2,预览3
我只是修改我的清单,添加新活动:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.youactive.hts.youactive">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="YouactiveSlidingMenu"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".SplashScreenActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
这是我的SplashScreenActivity.java
package me.youactive.hts.youactive;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class SplashScreenActivity extends AppCompatActivity
{
private final int SPLASH_DISPLAY_LENGTH = 3000;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
}
@Override
protected void onResume()
{
super.onResume();
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
// Obtain the sharedPreference, default to true if not available
boolean isSplashEnabled = sp.getBoolean("isSplashEnabled", true);
if (isSplashEnabled)
{
new Handler().postDelayed(new Runnable()
{
@Override
public void run()
{
//Finish the splash activity so it can't be returned to.
SplashScreenActivity.this.finish();
// Create an Intent that will start the main activity.
Intent mainIntent = new Intent(SplashScreenActivity.this, MainActivity.class);
SplashScreenActivity.this.startActivity(mainIntent);
}
}, 3000);
}
else
{
// if the splash is not enabled, then finish the activity immediately and go to main.
finish();
Intent mainIntent = new Intent(SplashScreenActivity.this, MainActivity.class);
SplashScreenActivity.this.startActivity(mainIntent);
}
}
}
如果我更改了清单,并放置了主要的MainActivity,则应用程序将成功启动
在我的运行窗口中,我可以看到此消息:
adb shell am start -n&#34; me.project.com.project / me.project.com.project.MainActivity&#34; -a android.intent.action.MAIN -c android.intent.category.LAUNCHER 客户尚未准备好......
我在SO中读过一些类似的问题,即添加&#34; android:exported =&#34; true&#34;在Manifest中可以解决这个问题,但在我的情况下它不会。
答案 0 :(得分:0)
您的wifi连接可能是此错误的原因。
在进行任何与代码相关的更改之前重新连接到wifi可能是个好主意。