アプリが最初に起動された場合、このコードがあります。初めて起動するとRegisterアクティビティが表示され、2回目の起動時にMainAcitivityが表示されます。最初の起動時にアクティビティのボタンがクリックされていないか確認してください。
Boolean isFirstRun = getSharedPreferences("PREFERENCE", MODE_PRIVATE).getBoolean("isFirstRun", false);
if (isFirstRun) {
startActivity(new Intent(Register.this, MainActivity.class));
//Toast.makeText(Register.this, "Authenticated", Toast.LENGTH_LONG) .show();
//finish the application after first run
finish();
}
{
getSharedPreferences("PREFERENCE", MODE_PRIVATE).edit().putBoolean("isFirstRun", true).commit();
// finish();
}
上記のコードは正常に動作しますが、ユーザーはレジスタ・アクティビティのボタンをクリックし、もう一度アプリを起動していない場合、それはMainActivityにユーザーをとり、これにより、ユーザは登録されませんでしたが、アプリを利用します。最初の起動時に登録アクティビティのボタンがクリックされたことを確認する方法と、ユーザーを登録アクティビティに戻す方法を確認する方法はありますか。ユーザ登録
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/phone"
android:layout_centerVertical="true"
android:text="Username"/>
<EditText
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:ems="10" />
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/username"
android:layout_below="@+id/username"
android:text="Phone No" />
<EditText
android:id="@+id/phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/TextView01"
android:layout_centerHorizontal="true"
android:ems="10"/>
<Button
android:id="@+id/register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/phone"
android:layout_below="@+id/phone"
android:text="Register" />
更新されたコード
@Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.register) {
// if(!validate()){
// call AsynTask to perform network operation on separate thread
new HttpAsyncTask().execute("http://xyz/create");
//new AttemptRegistration().execute();
// }
Boolean isFirstRun = getSharedPreferences("PREFERENCE", MODE_PRIVATE).getBoolean("isFirstRun", false);
if (isFirstRun) {
//show start activity
startActivity(new Intent(Register.this, MainActivity.class));
//Toast.makeText(Register.this, "Authenticated", Toast.LENGTH_LONG) .show();
//finish the application after first run
finish();
}
{
getSharedPreferences("PREFERENCE", MODE_PRIVATE).edit().putBoolean("isFirstRun", true).commit();
// finish();
}
}
ため
がXMLレジスタ活性のボタンがクリックされたことを、私はチェックを置くことができる方法はあります
あなたはボタンのクリック – Vucko
にRegisterActivityであなたのSharedPreferencesに '真' に置く必要がある私を見る......... – Blaze
このようなボタンonclickListener、googleを追加する方法を 'onClick'メソッドで設定します。これは最初の実行ではないので、** false **にブール値を設定します。 – Vucko