2014-04-25 138 views
0

我想知道为什么我的应用程序在恢复应用程序时忽略了我的SplashScreen.java活动。如果我用“返回”按钮关闭它,初始屏幕出现,但是如果我用主页按钮退出,则不会调用SplashScreen活动...... :(恢复应用程序时忽略初始屏幕活动 - Android

我甚至添加了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(); 
    } 

} 

Maifest:

... 

<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>  


... 
+0

你想在用户启动/回到你的应用程序时始终显示启动画面? – eleven

+0

'如果我用主页按钮退出,不,你不退出。你把你的应用程序放在后台。 –

+0

扯掉自己的用户是相当错误的策略。您只能在应用程序启动时显示启动画面。如名称所示,恢复应用程序应在用户离开它的地方恢复。 –

回答

-1

当您单击后退按钮实际上是活动越来越成品,当你回来的闪屏显示。这是因为再次开始应用。

当您单击主页按钮时,活动未完成,但会转到背景,并且当您一次打开该应用程序时,同样的活动将被购买到前台。所以不显示启动画面。

它在应用程序的生命周期中如何工作。

尝试在活动的暂停中调用finish();方法。所以它会一直完成。或者尝试将noHistory添加到清单中的活动。希望这会帮助你。

+0

感谢您的建议! –

+1

它不是一个正确的扫管笏管理一个应用程序,我猜那是你有一个-1,所以当你这样做时,请注意它不是一个正确的方法来解决这个问题,即使这sactisfies你的要求,应用程序不再一次启动。 –

2

尝试THI秒。

改变这个..

Intent mainActivity = new Intent("com.exploreca.tourfinder.MainActivity"); 
startActivity(mainActivity); 

+1

hi @Hariharan - 我已经添加了,但没有区别。 :( –

相关问题