0

In my app I am uploading an image to a server,a notification progress bar is there to show upload progress.when a user click on the notification ,a popup window will show to cancel or continue upload.All these are working fine.When I click back button and when I am at previous activity,if I click notification the popup window will not be displayed instead it only load the Activity for file Upload.How can I solve this issue??.When user clicks on the notification a pending Intent will be passed and at onNewIntent method I am calling popup window method.This is working fine when I am on the file upload activity.I don't know what is the actual problem.I think the pending intent is deals with another intent in my onCreate method, Can anyone help??

Pending Intent on Notification progress

 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 method

 @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 method

 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();

    }
};
Jack
  • 1,825
  • 3
  • 26
  • 43

1 Answers1

0

On pressing back from ImageUploadActivity it has been removed from the activity backstack so when the user click on notification the pendingIntent create a new instance of the activity.OnNewIntent() always get called for singleTop/Task activities except for the first time when activity is created. At that time onCreate is called.

In onCreate() of ImageUploadActivity you can call onNewIntent(getIntent()), In onNewIntent() check if extras isn't null and contains first_state.

Pr38y
  • 1,565
  • 13
  • 21
  • Ok i called onNewIntent(getIntent()); in my onCreate method .But still the initiatePopupWindow(); method is not executing but the Toast on the newIntent is working(Any idea?) – Jack Jul 09 '15 at 08:21
  • can you check my initiatePopupWindow(); method – Jack Jul 09 '15 at 08:23
  • Are you calling `pwindo.showAsDropDown` in `initiatePopupWindow` ? where are you calling show method on `pwindo`? – Pr38y Jul 09 '15 at 08:51
  • This is the code ,pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0); – Jack Jul 09 '15 at 09:14
  • state is 3? and is there any exception in your try catch block? – Pr38y Jul 09 '15 at 09:19
  • Hai ,there is no exception in catch block ,now a Toast inside the if condition also works,but popup window is not shown.And if i click again on notififcation the popup will be shown.I don't know wht is happening – Jack Jul 09 '15 at 09:31
  • I think you can help me..I am fed up with this,already spent 2 days for this – Jack Jul 09 '15 at 09:36
  • in `pwindo.showAtLocation` first parameter should be parent view not the popupwindow view itself. pass the parent layout reference of the activity. for more info please check herer http://stackoverflow.com/questions/7926689/androidpopupwindow-showatlocation – Pr38y Jul 09 '15 at 10:51
  • Is it possible to pass parent layout reference there ?? – Jack Jul 09 '15 at 10:54
  • Hi I have checked the link, please see this line of code :- View layout = inflater.inflate(R.layout.popupmenu, (ViewGroup) findViewById(R.id.popup_element)); – Jack Jul 09 '15 at 11:46
  • The parent view is popupmenu,I think my code is correct – Jack Jul 09 '15 at 11:47
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/82898/discussion-between-pr38y-and-jaxon). – Pr38y Jul 10 '15 at 07:40