如何处理通知进度条上的待定意图?

How to Handle Pending Intent on Notification Progress bar?

在我的应用程序中,我正在将图像上传到服务器,那里有一个通知进度条来显示上传 progress.when 用户点击通知,弹出窗口 window 将显示取消或继续 upload.All 这些正在工作 fine.When 我单击后退按钮,当我在上一个 activity 时,如果我单击通知,弹出窗口 window 将不会显示,而只会加载Activity 对于文件 Upload.How 我可以解决这个问题吗??。当用户点击通知时,将传递一个未决的 Intent 并且在 onNewIntent 方法中我调用弹出窗口 window method.This当我上传文件时工作正常 activity.I 不知道实际是什么 problem.I 认为未决意图处理我的 onCreate 方法中的另一个意图,有人可以帮忙吗?

通知进度的待定意向

 public void ProgressBarNotification() {
            mBuilder = new NotificationCompat.Builder(ImageUploadActivity.this);
            mBuilder.setContentTitle("Upload")
                        .setContentText("Upload in progress")
                        .setSmallIcon(R.drawable.ic_launcher);

  mBuilder.setProgress(100, 0, false);

    mBuilder.setAutoCancel(true);
  Intent myIntent = new Intent(this, ImageUploadActivity.class);  //Pending Intent
  myIntent.putExtra("first_state",3);
  PendingIntent pendingIntent = PendingIntent.getActivity(ImageUploadActivity.this, 1, myIntent, PendingIntent. FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(pendingIntent);
    mNotifyManager.notify(MY_NOTIFICATION_ID, mBuilder.build());
}

onNewIntent 方法

 @Override
 protected void onNewIntent(Intent intent) {
   super.onNewIntent(intent);
    //new Intent(this, ImageUploadActivity.class);
   Bundle extras = intent.getExtras();
   state = extras.getInt("first_state");

      if(state==3)
  { 
   initiatePopupWindow();
   }}

InitiatePopupwindow 方法

 public void initiatePopupWindow() {
    try {

        LayoutInflater inflater = (LayoutInflater) ImageUploadActivity.this
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.popupmenu,
                (ViewGroup) findViewById(R.id.popup_element));
        pwindo = new PopupWindow(layout, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
        pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);
        pwindo.setFocusable(true);
        pwindo.setOutsideTouchable(true);
        Button btnStopUpload = (Button) layout.findViewById(R.id.btn_upload);
        btnStopUpload.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                mNotifyManager.cancel(MY_NOTIFICATION_ID);
                //  mTask.cancel(true);
                Log.e(TAG, "Notification Cancelled ");
                // mTask.cancel(true);
                Toast.makeText(getApplicationContext(),
                        "Upload Cancelled", Toast.LENGTH_SHORT).show();
                ImageUploadActivity.this.finish();
            }
        });


        Button btnCancelPopup = (Button) layout.findViewById(R.id.btn_cancel);

        btnCancelPopup.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                pwindo.dismiss();

            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}

private View.OnClickListener cancel_button_click_listener = new View.OnClickListener() {
    public void onClick(View v) {
        pwindo.dismiss();

    }
};

ImageUploadActivity 按下后,它已从 activity 后退堆栈中删除,因此当用户单击通知时,pendingIntent 创建 activity 的新实例。OnNewIntent() 总是会调用 singleTop/Task 活动,但第一次创建 activity 时除外。那个时候叫onCreate.

ImageUploadActivityonCreate() 中你可以调用 onNewIntent(getIntent()),在 onNewIntent() 中检查 extras 是否不为 null 并且包含 first_state .