2017-11-21 2 views
0

私のアプリのイントロ画面を確認する必要があります初めて開くか、それが初めて開かれたりされていないアプリをチェックしていない...私の悪い英語のため申し訳ありません が あなたの助けを必要とする。これは、私のチェックコードである:最初に開かれたアプリをチェックする必要があるかどうかを確認する必要がある場合はメインアクティビティに進みます。そうでない場合はイントロ画面に進みます。

intromanager = new Intromanager(this); 
     if(!intromanager.Check()){ 
      intromanager.setFirst(false); 
      Intent i = new Intent(IntroActivity.this,MainActivity.class); 
      startActivity(i); 
      finish(); 
     } 

クラス:

public class Intromanager { 
    SharedPreferences pref; 
    SharedPreferences.Editor editor; 
    Context context; 

    public Intromanager(Context context){ 
     this.context = context; 
     pref = context.getSharedPreferences("first", 0); 
     editor = pref.edit(); 
    } 

    public void setFirst(boolean isFirst){ 
     editor.putBoolean("check",isFirst); 
     editor.commit(); 
    } 

    public boolean Check(){ 
     return pref.getBoolean("check",true); 
    } 
} 

答えて

0

コードの下に試してみてください。

intromanager =new Intromanager(this); 
if(intromanager.Check()){ 
    intromanager.setFirst(false); 
} else { 
    Intent i = new Intent(IntroActivity.this, MainActivity.class); 
    startActivity(i); 
    finish(); 
} 



public class Intromanager { 
    SharedPreferences pref; 
    Context context; 

    public Intromanager(Context context){ 
     this.context = context; 
     pref = context.getSharedPreferences("first", Activity.MODE_PRIVATE); 
    } 

    public void setFirst(boolean isFirst){ 
     SharedPreferences.Editor editor = pref.edit(); 
     editor.putBoolean("check",isFirst); 
     editor.apply(); 
    } 

    public boolean Check(){ 
     return pref.getBoolean("check",true); 
    } 
} 
+0

私のクラスコードをアップロードするために行方不明申し訳ありません再度あなたのコードを再確認することができますsir – Keshab

+0

上記のコードをお試しください。それがあなたを助けることを願ってください。 –

+0

それは私のための仕事ですので、親切に助けてくれてありがとうございます。 – Keshab

関連する問題