2017-05-24 7 views
0

私はSplashActivityをアプリケーションの起動時に最初に登録するように設定しました。次に、私のAsyncTaskのpostExecuteメソッドで、MainActivityに移動する新しいインテントを開始します。なぜこれは機能しませんか?私は1つの例外を得ることはありません。アプリ単に私のMainAcitvityに開きます...たぶん私は再構築プロジェクトに数回をきれいにする必要があります...非同期スプラッシュアクティビティは表示されません

マニフェスト:

<activity 
      android:name=".activity.SplashActivity" 
      android:configChanges="keyboardHidden|orientation|screenSize" 
      android:label="@string/app_name" 
      android:launchMode="singleTask" 
      android:screenOrientation="portrait" > 
      <intent-filter> 
       <action android:name="android.intent.action.SEND" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
       <data android:mimeType="image/*" /> 
      </intent-filter> 
     </activity> 
    <activity 
     android:name=".activity.MainActivity" 
     android:configChanges="keyboardHidden|orientation|screenSize" 
     android:label="@string/app_name" 
     android:launchMode="singleTask" 
     android:screenOrientation="portrait" > 
    </activity> 

コード:

public class SplashActivity extends Activity { 

    private static final int SPLASH_SHOW_TIME = 40800; 

    @Override protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     setContentView(R.layout.splash); 
     new BackgroundSplashTask().execute(); 
    } 

    private class BackgroundSplashTask extends AsyncTask<Void, Void, Void> { 

     @Override 
     protected void onPreExecute(){ 
      super.onPreExecute(); 
     } 

     @Override 
     protected Void doInBackground(Void... arg0) { 
      try { 
       Thread.sleep(SPLASH_SHOW_TIME); 
      } catch (InterruptedException e) { 
       e.printStackTrace(); 
      } return null; 
     } 

     @Override 
     protected void onPostExecute(Void result) { 
      super.onPostExecute(result); 
      Intent i = new Intent(SplashActivity.this, MainActivity.class); 
      startActivity(i); finish(); 
     } 

    } 

} 
+0

インテントフィルタでスプラッシュアクティビティが最初に開くように設定されていないか、ランチャに表示されません –

答えて

1

は、次のようにSplashActivityを設定します。また、onPreExecute()実装を削除してください。あなたのケースでは不要です。

private class BackgroundSplashTask extends AsyncTask<Void, Void, Void> { 

    @Override 
    protected Void doInBackground(Void... arg0) { 
     try { 
      Thread.sleep(SPLASH_SHOW_TIME); 
     } catch (InterruptedException e) { 
      e.printStackTrace(); 
     } return null; 
    } 

    @Override 
    protected void onPostExecute(Void result) { 
     Intent i = new Intent(SplashActivity.this, MainActivity.class); 
     startActivity(i); finish(); 
    } 

} 
1

マニフェストにこれらの2行を追加する必要があります。SplashActivity

<intent-filter> 
    <action android:name="android.intent.action.MAIN" /> 
    <category android:name="android.intent.category.LAUNCHER" /> 
</intent-filter> 

これが役に立ちます。

<activity android:name=".activity.SplashActivity" 
     android:configChanges="keyboardHidden|orientation|screenSize" 
     android:label="@string/app_name" 
     android:launchMode="singleTask" 
     android:screenOrientation="portrait" >> 
    <intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 

     <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
</activity> 

を次に、あなたのAsycTask以内に、ちょうどあなたのonPostExecute(Void result)方法からコードのsuper.onPostExecute(result);行を削除します。あなたのAndroidManifest.xmlファイルで

関連する問題