2014-03-19 60 views
0

我無法更改應用程序的啓動活動。在開始我的開始活動是com.example.image_changer.MainActivity和這個我的應用程序正常運行。然後我將我的啓動活動從MainActivity更改爲com.example.image_changer.Splash。但我的應用程序不啓動com.example.image_changer.Splash活動。

我想com.example.image_changer.Splash作爲我的應用程序的開始活動。

我曾嘗試以下解決方案:

1.在Eclipse中,我更改此設置:運行菜單 - >調試配置---->在我的應用程序---> Android的標籤--->行動啓動---->啓動(單選按鈕)---->選擇(從下拉菜單中)--->com.example.image_changer.Splash
無法更改應用程序的啓動活動 - Android



2.互聯網搜索:

我已經試過此鏈接給所有的解決方案:Change application's starting activity

在這個環節zeh(用戶)發表評論,這可能看起來像同我的問題,但沒有人提出更好的解決方案。

注意,當我運行我的程序,然後運行splash.java但不顯示模擬器的屏幕上,我知道這是因爲我的代碼System.out.println();在splash.java線程,它打印字符串在控制檯每次當我運行我的應用程序。

那麼如何解決這個問題呢?

這是我的清單:

<uses-sdk 
    android:minSdkVersion="14" 
    android:targetSdkVersion="17" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/imagechanger" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="com.example.image_changer.Splash" 
      > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity android:name="com.example.image_changer.MainActivity1"></activity> 
    <activity android:name="com.example.image_changer.GamesFragment"></activity> 
    <activity android:name="com.example.image_changer.MoviesFragment"></activity> 
    <activity android:name="com.example.image_changer.TabsPagerAdapter"></activity> 
    <activity android:name="com.example.image_changer.TopRatedFragment"></activity> 
    <activity android:name="com.example.image_changer.Imageswipe"></activity> 
    <activity android:name="com.example.image_changer.Mapview"></activity> 

    <activity 
     android:name="com.example.image_changer.MainActivity" 
     android:label="@string/app_name"></activity> 


</application> 

</manifest> 

這是我Splash.java類文件

package com.example.image_changer; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.MotionEvent; 
import android.view.Window; 
import android.view.WindowManager; 

public class Splash extends Activity { 
/** Called when the activity is first created. */ 
private Thread mSplashThread;  

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
     WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     setContentView(R.layout.activity_splash); 
     //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 

     final Splash sPlashScreen = this; 

     // The thread to wait for splash screen events 
     mSplashThread = new Thread(){ 
      @Override 
      public void run(){ 
       try { 
        synchronized(this){ 
         // Wait given period of time or exit on touch 
         wait(2500); 

        } 
       } 
       catch(InterruptedException ex){      
       } 



       // Run next activity 

       Intent intent = new Intent(); 
       intent.setClass(sPlashScreen,MainActivity.class); 
       System.out.println("your are in the intent"); 
       startActivity(intent); 


       finish(); 
      } 
     }; 

     mSplashThread.start();   
    } 

    /** 
    * Processes splash screen touch events 
    */ 
    @Override 
    public boolean onTouchEvent(MotionEvent evt) 
    { 
     if(evt.getAction() == MotionEvent.ACTION_DOWN) 
     { 
      synchronized(mSplashThread){ 
       mSplashThread.notifyAll(); 
      } 
     } 
     return true; 
    } 
} 

回答

0

更新你的線程代碼這一點。

new Handler().postDelayed(new Runnable() { 
    public void run() { 
       // Run next activity 

       Intent intent = new Intent(); 
       intent.setClass(sPlashScreen,MainActivity.class); 
       System.out.println("your are in the intent"); 
       startActivity(intent); 


       finish(); 
     } 
}, 2500); 
+0

不工作,因爲我無法爲你張貼在這裏'新的處理程序()使用處理器postDelayed(新的Runnable(){',當我將此代碼日食給我一個錯誤';'或'}'missing。 –

+0

回答更新,現在就試試!讓我知道你是否仍然面臨編譯錯誤 –

+0

好吧,兄弟它的工作,但還有一個問題,我需要再次使用這個線程'public boolean onTouchEvent(MotionEvent如何在方法中使用這個線程或處理程序 –

相關問題