我正在创建一个正在android
使用的备份应用程序,BackupManager
但由于备份实际上在计划时间发生并没有及时,我只想知道如何显示一条被调用的消息dialogbox
,onBackup()
现在您的数据保存在谷歌服务器上。主要问题是对话框的上下文应该是什么?到目前为止我已经尝试过了,但是当onBackup()
被调用时它没有显示
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setTitle("BACKUP ALERT");
builder.setMessage("Your Backup has been processed");
builder.setPositiveButton("OK", null);
AlertDialog dialog = builder.show();
我在onBackup()
方法中写了这个,但它没有显示在我的应用程序上。我想在备份发生并且用户打开我的应用程序时显示此消息,或者如果他已经打开我想显示它,无论当时哪个活动是前台,或者有人可以告诉我如何notification
在 androidnotification
栏中使其成为一个。
我创建并显示对话框的行有错误Logcat
..
12-28 13:22:52.722: E/JavaBinder(16540): *** Uncaught remote exception! (Exceptions are not yet supported across processes.)
12-28 13:22:52.722: E/JavaBinder(16540): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
12-28 13:22:52.722: E/JavaBinder(16540): at android.os.Handler.<init>(Handler.java:121)
12-28 13:22:52.722: E/JavaBinder(16540): at android.app.Dialog.<init>(Dialog.java:107)
12-28 13:22:52.722: E/JavaBinder(16540): at android.app.AlertDialog.<init>(AlertDialog.java:118)
12-28 13:22:52.722: E/JavaBinder(16540): at android.app.AlertDialog$Builder.create(AlertDialog.java:971)
12-28 13:22:52.722: E/JavaBinder(16540): at com.vahzay.android.smstrove.MySmsBackupAgent1.onBackup(MySmsBackupAgent1.java:233)
12-28 13:22:52.722: E/JavaBinder(16540): at android.app.backup.BackupAgent$BackupServiceBinder.doBackup(BackupAgent.java:490)
12-28 13:22:52.722: E/JavaBinder(16540): at android.app.IBackupAgent$Stub.onTransact(IBackupAgent.java:80)
12-28 13:22:52.722: E/JavaBinder(16540): at android.os.Binder.execTransact(Binder.java:338)
12-28 13:22:52.722: E/JavaBinder(16540): at dalvik.system.NativeStart.run(Native Method)
我的对话框代码是:
new AlertDialog.Builder(getApplicationContext())
.setMessage("Backup Alert")
.setPositiveButton("Ok", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface arg0, int arg1)
{
Toast.makeText(getApplicationContext(), "Your SMS Record that you requested to backup earlier is now processed", Toast.LENGTH_LONG).show(); //-->233
}
}).create().show();
}