我的应用程序在启动画面后停止工作 - 请记住,这是我开发的第一个Android应用程序。非常感谢帮助。
SplashScreen.java:
package tomperry.goodlife;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class SplashScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timerThread = new Thread() {
public void run() {
try {
sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Intent intent = new Intent();
startActivity(intent);
}
}
};
timerThread.start();
}
@Override
protected void onPause() {
super.onPause();
finish();
}
}
AndroidManifist.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tomperry.goodlife">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity android:name=".SplashScreen"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN"
></action>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="tomperry.goodlife.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
答案 0 :(得分:1)
您的Intent
为空。你没告诉他去哪儿。将其替换为finally
块 -
Intent intent = new Intent(SplashScreen.this, NextActivity.class); //Change "NextActivity" as your need
startActivity(intent);
finish();
答案 1 :(得分:1)
您尚未提及主要活动。
试试这个
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
而不是
Intent intent = new Intent();
startActivity(intent);
答案 2 :(得分:0)
从清单文件中的主要活动中删除意图过滤器
<intent-filter>
<action android:name="tomperry.goodlife.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
答案 3 :(得分:0)
您没有添加目的地去哪里。在最后阻止你的Intent是空的。所以将此代码行更改为finally块:
ProcessBuilder
到
Intent intent = new Intent();
答案 4 :(得分:0)
只需将finally
块替换为:
startActivity(new Intent(Splashscreen.this,MainActivity.class));