如何獲得後臺進程的結果,在任何Activity
?顯示從後臺進程的警告對話框中的任何活動
我與OTA更新工作。應用程序在處理程序中處理後臺。更新完成後,我必須向用戶顯示警報對話框。我可以在SettingsActivity
中顯示它,我從OTA開始,但用戶可以在任何其他Activity
。
private void checkIsUpdated() {
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mDevice.getDevice().read(GattUUID.LS_DEVICE_INFORMATION, GattUUID.LC_FIRMWARE, new
BleDevice.ReadWriteListener() {
@Override
public void onEvent(ReadWriteEvent e) {
if (e.wasSuccess()) {
if (firmwareVersion.equals(e.data_string())) {
showAlertDialog("OTA update failed", "Device is not updated");
} else {
showAlertDialog("OTA update is successful.\nDevice is updated to new " +
"firmware!", "Device is updated");
}
Log.i("OTA", "Read firmware is new success");
} else {
Log.e("OTA", "Read firmware is new success");
}
}
});
}
}, 30000);
}
AlertDialog
代碼
private void showAlertDialog(String message, String title) {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext, R.style.SwipeDialogLight);
builder.setTitle(title)
.setMessage(message)
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
if (!alert.isShowing()) {
alert.show();
}
}
你試過廣播接收器嗎? – rogerwar
我必須在每項活動中註冊它嗎? – Adnan
我想只是爲了提醒對話框,只能從應用程序的啓動畫面進行註冊。 – rogerwar