我想使用广播接收器在固定时间调用此方法的警报
/**
* Delete all messages
*/
private void performDeleteAll() {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(getString(R.string.confirm_message))
.setCancelable(false)
.setNegativeButton(getString(R.string.confirm_no),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
.setPositiveButton(getString(R.string.confirm_yes),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// delete all messages
mHandler.post(mDeleteAllMessages);
adapter.refresh();
}
});
AlertDialog alert = builder.create();
alert.show();
}
删除所有消息但它没有发生请帮助我提前感谢
/** * 删除所有消息。0 - 成功删除。1 - 没有要删除的内容。*/
final Runnable mDeleteAllMessages = new Runnable() {
public void run() {
getActivity().setProgressBarIndeterminateVisibility(true);
boolean result = false;
int deleted = 0;
if (adapter.getCount() == 0) {
deleted = 1;
} else {
result = model.deleteAllMessages();
}
try {
if (deleted == 1) {
toastLong(R.string.no_messages_to_delete);
} else {
if (result) {
toastLong(R.string.messages_deleted);
showMessages();
} else {
toastLong(R.string.messages_deleted_failed);
}
}
getActivity().setProgressBarIndeterminateVisibility(false);
} catch (Exception e) {
return;
}
}
};
我正在使用这个广播接收器
public class AlarmReceiver extends BroadcastReceiver implements Runnable {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Toast.makeText(context, "Import Messages Invoke ",Toast.LENGTH_LONG).show();
// context.startService(new Intent(context,ImportMessagesTask.class));
MessagesModel.deleteAllMessages();{
// new MessagesModel().deleteAllMessages();
Database.mMessagesContentProvider.deleteAllMessages();
}
// mHandler.post(mDeleteAllMessages);
// adapter.refresh();
正如你所说,我做了我创建了一个活动
公共类 Activity 扩展 PendingMessages 实现 Runnable{
/**
* Delete all messages. 0 - Successfully deleted. 1 - There is nothing to be
* deleted.
*/
@Override
public void run() {
// TODO Auto-generated method stub
getActivity().setProgressBarIndeterminateVisibility(true);
boolean result = false;
int deleted = 0;
if (adapter.getCount() == 0) {
deleted = 1;
} else {
result = model.deleteAllMessages();
}
try {
if (deleted == 1) {
toastLong(R.string.no_messages_to_delete);
} else {
if (result) {
toastLong(R.string.messages_deleted);
showMessages();
} else {
toastLong(R.string.messages_deleted_failed);
}
}
getActivity().setProgressBarIndeterminateVisibility(false);
} catch (Exception e) {
return;
}
}
}
然后通过调用它
context.startService(new Intent(context,Activity.class));
但它不工作,然后我称之为通过
context.startActivity(new Intent(context,Activity.class));
然后它关闭的力量我没有得到任何帮助请让我正确提前谢谢