我有一个自定义对话框活动类,当我必须显示特定进程的等待栏时调用它,之后我调用它的完成方法但我无法在那里完成该活动或者我不知道如何调用它完成方法,但我通过类的对象调用它,我的WaitDialogManager
类代码如下。而且我不想为此使用广播接收器...
等待对话管理器
包 com.android.remotewipedata;
导入android.app.Activity;导入android.os.Bundle;导入android.view.Window;导入 android.widget.TextView;
公共类 WaitDialogManager 扩展 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()
方法结束时关闭/消失。谢谢