2011-08-06 7 views
0

登録ページとアカウント作成ページが必要です。アカウントの作成ページで情報を入力した後、アカウント作成に成功したか、コードが再送信されたかを示すダイアログボックスが表示された登録ページに戻ります。前のアクティビティで行ったことに基づいて、別のアクティビティでダイアログボックスを表示する方法

現在のところ、ウェブサーバーの応答を確認していますが、状況によってはダイアログボックスが表示され、アカウントの作成アクティビティが閉じ、ダイアログボックスがポップアップしている間に背景に登録ページが表示されますアカウントが作成されるか、コードが再送信されます。

しかし、現在のところ、ダイアログボックスを表示せずに自分のアクティビティを閉じることができます。私は登録ページでダイアログを開く必要があると仮定していますが、作成されたか再送信されたかを尋ねる方法はわかりません。私が言ったことに基づいて適切なダイアログを表示する方法についてのヒントを教えていただけたら、私はとても感謝しています。

はここ

は私のコードは ノートであるあなたがあなたのAlertDialogビルダーのsetNeutralButtonで情報を記入

public void btnCreate(View v) throws Exception { 
    // if we get to here we can send the information to the webserver 

    String response = makeRequest(email.getText().toString(), fName 
      .getText().toString(), lName.getText().toString()); 
    if (response != null) { 
     org.json.JSONObject obj = new org.json.JSONObject(response); 
      //response is created make created dialog 
     if ("Created".equals(obj.getString("status"))) { 
      new AlertDialog.Builder(CreateAccount.this) 
        .setTitle("Account Creation Successful") 
        .setMessage(
          "An activation code has been sent to you. Please check your SPAM folder if you do not receive your activation code email") 
        .setNeutralButton("OK", null).show(); 
     // response is resend and sends the resend dialog 
     } else if ("Resend".equals(obj.getString("status"))) { 
      new AlertDialog.Builder(CreateAccount.this) 
        .setTitle("Code Resent") 
        .setMessage(
          "Your activation code has been resent to your email.\n\nIf you are not receiving your activation code, our email is being blocked. Please email us at '[email protected]' and we will manually send you a code.") 
        .setNeutralButton("OK", null).show(); 
     } 
    } 
     //finishes this activity and shows the registration activity (the one before create account) 
    finish(); 

} 

答えて

1

自分自身に言及しているように、おそらく次のアクティビティでダイアログボックスを作成する必要があります。新しいアクティビティを開始するときに、アクティビティに余分な情報を渡すことができます。

だから、何かやって:次に、あなたの新しい活動にあなたは、単にだけ(のonCreate(新しい活動が作成されたときに受信したバンドルを取得することで、以前の活動から送られた余分な情報を取得

Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class); 
i.putExtra("login_successful", true); // Only true if they logged in. 
startActivity(myIntent); 

をBundle savedInstance))。

savedInstanceState = this.getIntent().getExtras(); 
boolean yes = savedInstanceState.getBoolean("login_successful"); 

もちろん、文字列やその他のプリミティブ型もバンドルに入れることができます。

Btwでは、次のアクティビティを表示するために現在のアクティビティを「終了」する必要はありません。ユーザーが別のユーザーとしてログアウトまたはログインしたい場合はどうしたらいいですか?アクティビティでfinishメソッドを呼び出すと、アクティビティスタックから削除され、アプリケーションを完全に再起動するまで取得できません。

+0

は完全に動作します。 。 – Sean

0

を終了した後、ボタンを押しDialogInterface.onClickListenerを設定し、あなたを行うありがとうそこで個々の活動を開始するロジック。

0

あなたの登録がActivityForResultになり、結果を返すように思えます。結果に基づいて、呼び出すアクティビティは異なる情報を表示することができます(結果は、インテントのように機能し、情報もパッケージ化されます)

関連する問題