0

特定のプロセスの待機バーを表示する必要があるときに呼び出すカスタム ダイアログ アクティビティ クラスがあります。その後、finish メソッドを呼び出しますが、そこでそのアクティビティを終了できないか、それを呼び出す方法がわかりません。メソッドを終了しますが、クラスのオブジェクトを介して呼び出していWaitDialogManagerます。クラスのコードは以下のとおりです。そして、そのためにブロードキャストレシーバーを使用したくありません...

WaitDialogManager

パッケージcom.android.remotewipedata;

android.app.Activity をインポートします。android.os.Bundle をインポートします。android.view.Window をインポートします。android.widget.TextView をインポートします。

public class WaitDialogManager extends Activity {

TextView waitTitle, waitMessage;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.wait_dialog);

    String title = getIntent().getStringExtra("waitDialogTitle");
    String message = getIntent().getStringExtra("waitDialogMessage");

    waitTitle = (TextView) findViewById(R.id.wait_dialog_title);
    waitMessage = (TextView) findViewById(R.id.wait_dialog_message);
    waitTitle.setText(title);
    waitMessage.setText(message);
}

public void dismissWaitDialog(){
    this.finish();
    System.out.println("Finish Called");
}
}

ここで、このアクティビティを呼び出し、メソッドの完了後に終了しようとしています。その非アクティビティ クラスのコードは以下のとおりです。

サーバーユーティリティ

public final class ServerUtilities {
    //Other code
public static WaitDialogManager wdManager = new WaitDialogManager();

static boolean register(final Context context, String name, String email,
        final String regId) {

            // Starting WaitDialogManager activity here
    context.startActivity(new Intent(context, WaitDialogManager.class)
            .putExtra("waitDialogTitle", "Please wait...")
            .putExtra("waitDialogMessage",
                    "Registering device on Server...")
            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));

    String serverUrl = SERVER_URL + "/register.php";
    Map<String, String> params = new HashMap<String, String>();
    params.put("regId", regId);
    params.put("name", name);
    params.put("email", email);

    // Try to register on server for a number of times
    long backoff = BACKOFF_MILLI_SECONDS + random.nextInt(1000);
    for (int i = 1; i <= MAX_ATTEMPTS; i++) {
        try {
            post(serverUrl, params);
            System.out.println("Parameters: " + params);
            GCMRegistrar.setRegisteredOnServer(context, true);
            return true;
        } catch (IOException e) {
            if (i == MAX_ATTEMPTS) {
                break;
            }
            try {
                Thread.sleep(backoff);
            } catch (InterruptedException e1) {
                Thread.currentThread().interrupt();
                return false;
            }
            backoff *= 2;
        }
    }
    wdManager.dismissWaitDialog();
    return false;
}

register()このダイアログを非表示にするには、戻るボタンを手動でクリックして非表示にしました。メソッドが終了したときに非表示/非表示にしたいです。ありがとう

4

2 に答える 2

0

私の経験では、技術的にこれを行うことはできません。ただし、2 番目のアクティビティを開始し、2startActivityForResult番目のアクティビティが終了したら、呼び出し元のアクティビティを終了する必要があることを示すフラグを返すことができます。このプロセスは非常に高速であるため、ユーザーは呼び出しアクティビティがまだ開いていることを認識できません。最初の/呼び出し元のアクティビティが常に終了する必要がある場合は、マニフェストandroid:noHistory="true"でアクティビティに設定できます。

于 2013-06-14T07:41:37.857 に答える
0

WaitDialogManager以下のように、クラスから現在のアクティビティの静的参照を取得して解決しました。クラスでWaitDialogManager静的Activity参照を宣言し、

public class WaitDialogManager extends Activity {

public static Activity context = null;   // Current Activity

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.wait_dialog);
            ....
}
}

ServerUtilitiesそしてそれを一撃のように呼び、

public final class ServerUtilities {
//Other code

static boolean register(final Context context, String name, String email,
    final String regId) {

        // Starting WaitDialogManager activity here
         context.startActivity(new Intent(context, WaitDialogManager.class)
        .putExtra("waitDialogTitle", "Please wait...")
        .putExtra("waitDialogMessage",
                "Registering device on Server...")
        .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));

String serverUrl = SERVER_URL + "/register.php";
Map<String, String> params = new HashMap<String, String>();
params.put("regId", regId);
params.put("name", name);
params.put("email", email);

// Try to register on server for a number of times
long backoff = BACKOFF_MILLI_SECONDS + random.nextInt(1000);
for (int i = 1; i <= MAX_ATTEMPTS; i++) {
    try {
        post(serverUrl, params);
        System.out.println("Parameters: " + params);
        GCMRegistrar.setRegisteredOnServer(context, true);
        WaitDialogManager.context.finish(); // And this is how it works
        return true;
    } catch (IOException e) {
        // Exception handled
    }
}
return false;
}
于 2013-06-17T06:40:42.067 に答える