2016-10-09 19 views
0

おはようスプラッシュ画面の後にAndroidアプリが続行されない

私のアプリがスプラッシュ画面の後にメインアクティビティを続行しないという問題が発生しました。最初にインストールされたときにメインアクティビティに進みますが、それ以降はメインアクティビティに移動します。

私はこれらの記事の両方を見てきました: token=android.os.BinderProxy error android? Timer stops working after app resume (Android)

それらのどちらも完全にguestionに答え、私の例とは異なります。

本質的に、EULAを受理してからメインアクティビティに入る必要があります。彼らがEULAを受諾せずにAppから出ると、彼らは再び入るときにEULAに転送されます。ここ

アクティビティコードされている次のよう

public class Splash extends AppCompatActivity { 

boolean a; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_splash); 


    final SharedPreferences settings = getSharedPreferences("prefs", 0); 
    final boolean firstRun = settings.getBoolean("firstRun", false); 
    final SharedPreferences disc = getSharedPreferences("disc", 0); 
    final boolean disclaimer = disc.getBoolean("disclaimer", false); 


    Thread thread = new Thread() { 
     @Override 
     public void run() { 

      try { 
       sleep(1500); 
      } catch (InterruptedException e) { 
       e.printStackTrace(); 
      } finally { 


       if (!firstRun) { 
        SharedPreferences.Editor editor = settings.edit(); 
        editor.putBoolean("firstRun", true); 
        editor.apply(); 
        Intent i = new Intent(Splash.this, Instruction.class); 
        startActivity(i); 
        finish(); 


       } else { 
        try { 
         Bundle bundle = getIntent().getExtras(); 
         a = bundle.getBoolean("key"); 

         if (a == true) { 
          SharedPreferences.Editor editor = disc.edit(); 
          editor.putBoolean("disclaimer", true); 
          editor.apply(); 

          Intent i = new Intent(Splash.this, siteCheck.class); 
          startActivity(i); 
         } 
        } catch (Exception e) { 

         if (disclaimer == true) { 
          Intent i = new Intent(Splash.this, siteCheck.class); 
          startActivity(i); 
         } else { 
          Intent d = new Intent(Splash.this, Instruction.class); 
          startActivity(d); 
         } 

        } 
       } 

      } 
     } 


    }; 
    thread.start(); 


} 

@Override 
protected void onPause() { 
    super.onPause(); 
    finish(); 

} 


@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.global, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 

    //noinspection SimplifiableIfStatement 


    return super.onOptionsItemSelected(item); 
} 

}

LogCatである:

10-09 12:26:36.820 10246-10246/? I/Timeline: Timeline: Activity_idle id: [email protected] time:16608813 

これは、それが終了メッセージです。それはそこから続くのではなく、スプラッシュ画面にとどまります。

スレッドの使用に関連する可能性はありますか?それでは、なぜ今だけで開発の初期段階ではないのですか?

私は本当に助け、指導またはアドバイスをいただきありがとうございます。

ご協力いただきありがとうございます。

+0

おそらくfirstRunであり、キーはfalseです。 *スレッドの使用に関連する可能性がありますか?いいえ、それはありません。 – Blackbelt

+0

大丈夫です。私はすぐにそれを調べます。どうもありがとうございます。 – Dietmar

+0

すべてのlogcatプリント?これ以上何もない ? –

答えて

0

あなたの活動をsplashScreenから開始するには、以下のコードを使用してください:finish();

Handler h = new Handler(Looper.getMainLooper()); 
    h.postDelayed(() -> { 
     if (!firstRun) { 
       SharedPreferences.Editor editor = settings.edit(); 
       editor.putBoolean("firstRun", true); 
       editor.apply(); 
       Intent i = new Intent(Splash.this, Instruction.class); 
       startActivity(i); 
       finish(); 
      } else { 
       try { 
        Bundle bundle = getIntent().getExtras(); 
        a = bundle.getBoolean("key"); 

        if (a == true) { 
         SharedPreferences.Editor editor = disc.edit(); 
         editor.putBoolean("disclaimer", true); 
         editor.apply(); 

         Intent i = new Intent(Splash.this, siteCheck.class); 
         startActivity(i); 
        } 
       } catch (Exception e) { 

        if (disclaimer == true) { 
         Intent i = new Intent(Splash.this, siteCheck.class); 
         startActivity(i); 
        } else { 
         Intent d = new Intent(Splash.this, Instruction.class); 
         startActivity(d); 
        } 

       } 
      } 
    }, 1500); 
+0

あなたは 'siteCheck'アクティビティを開始する場合にスプラッシュアクティビティを終了したくありませんか? –

+0

Amir Ziaritiというコードをありがとうございました。私は今それを調べます。ほんとうにありがとう! – Dietmar

0

このようなスレッドは使用しないでください。ハンドラを使用することができます。

new Handler().postDelayed(new Runnable() { 

      @Override 
      public void run() { 

       if (!firstRun) { 
        SharedPreferences.Editor editor = settings.edit(); 
        editor.putBoolean("firstRun", true); 
        editor.apply(); 
        Intent i = new Intent(Splash.this, Instruction.class); 
        startActivity(i); 
        finish(); 


       } else { 
        try { 
         Bundle bundle = getIntent().getExtras(); 
         a = bundle.getBoolean("key"); 

         if (a == true) { 
          SharedPreferences.Editor editor = disc.edit(); 
          editor.putBoolean("disclaimer", true); 
          editor.apply(); 

          Intent i = new Intent(Splash.this, siteCheck.class); 
          startActivity(i); 
         } 
        } catch (Exception e) { 

         if (disclaimer == true) { 
          Intent i = new Intent(Splash.this, siteCheck.class); 
          startActivity(i); 
         } else { 
          Intent d = new Intent(Splash.this, Instruction.class); 
          startActivity(d); 
         } 

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

申し訳ありません、本当に助けてくれてありがとう! – Dietmar

関連する問題