【发布时间】:2014-04-25 10:46:25
【问题描述】:
我想知道为什么我的应用程序在恢复应用程序时忽略了我的 SplashScreen.java 活动。如果我用“返回”按钮关闭它,启动时会出现启动画面,但如果我用主页按钮退出,则不会调用 SplashScreen 活动...:(
我什至添加了 onResume 事件,但在恢复我的应用程序时仍然不会出现启动画面。 谢谢!!
SplashScreen.java
public class Splash extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
spashStart();
}
protected void onResume(){
super.onResume();
spashStart();
}
private void spashStart() {
Thread splashTimer = new Thread() {
public void run(){
try{
sleep(5000);
Intent mainActivity = new Intent("com.exploreca.tourfinder.MainActivity");
startActivity(mainActivity);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
finish();
}
}
};
splashTimer.start();
}
}
梅菲斯特:
...
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/scena_logo"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.exploreca.tourfinder.Splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.exploreca.tourfinder.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"
android:parentActivityName="com.exploreca.tourfinder.MainActivity">
</activity>
<activity
android:name=".TourDetailActivity"
android:parentActivityName="com.exploreca.tourfinder.MainActivity">
</activity>
<activity
android:name=".NotificationDetails"
android:label="@string/title_activity_notifDetails_title"
android:parentActivityName="com.exploreca.tourfinder.MainActivity">
</activity>
<activity
android:name=".SavedEvents"
android:label="@string/title_activity_SavedEvents"
android:parentActivityName="com.exploreca.tourfinder.MainActivity">
</activity>
<activity
android:name=".FollowList"
android:label="@string/title_activity_Urmarite"
android:parentActivityName="com.exploreca.tourfinder.MainActivity">
</activity>
...
【问题讨论】:
-
您希望在用户启动/返回您的应用时始终显示启动画面?
-
if I exit with the home button,不,你不要退出。您将应用置于后台。 -
惹恼自己的用户是相当错误的策略。您应该仅在应用启动时显示启动画面。顾名思义,恢复应该在用户离开的地方恢复应用。
-
@Marcin Orlowski - 也许你是对的,谢谢。
标签: android android-activity splash-screen onresume