显示警报消息onReceive方法的广播接收器

时间:2013-09-07 06:08:06

标签: android android-intent service android-service

在我的应用程序中

在上传所有图像后,图像将在IntentService上传到服务器上。意图服务发送广播,onReceive方法接收响应并显示适当的警报消息。但是,如果我的应用暂停或其他应用程序被激活,并且在我的应用程序打开后,则不会显示警报消息。如果我的应用程序在前台,它将显示警报消息。如何解决此问题,我是否应该在下载完整检查布尔值onresume方法时使用 IntentService 中的boolean共享首选项,并在用户打开我的应用时显示警告?

/*getting response from service*/
    BroadcastReceiver br=new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("recived", "service broadcast");
        String response=intent.getStringExtra("response");
        if(response.equals("null"))
        {
            AlertDialog alert = new AlertDialog.Builder(
                    Note_Signature_activity.this).create();
            alert.setTitle("Connection Time Out");
            alert.setCancelable(false);
            alert.setMessage("Connection Time Out Please Check Your Internet Connection");
            alert.setIcon(android.R.drawable.ic_dialog_info);
            alert.setButton(AlertDialog.BUTTON_NEGATIVE, "OK",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                int which) {
                            final_submit_button.setClickable(true);
                            pb.dismiss();
                        }
                    });
            alert.show();
        }
        else
        {
            final_submit_button.setClickable(true);
            AlertDialog alert = new AlertDialog.Builder(
                    Note_Signature_activity.this).create();
            alert.setTitle("Success");
            alert.setCancelable(false);
            alert.setMessage("Congratulations Successfully Submitted!");
            alert.setIcon(android.R.drawable.ic_dialog_info);
            alert.setButton(AlertDialog.BUTTON_NEGATIVE, "OK",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                int which) {
                            final_submit_button.setClickable(false);
                            pb.dismiss();
                            clear_main_history();
                            Intent select_trip_section=new Intent(Note_Signature_activity.this, SelectTripActivity.class);
                            select_trip_section.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            startActivity(select_trip_section);
                        }
                    });
            alert.show();
        }
    }
};
/**/

0 个答案:

没有答案