0

i've a service that sometimes call an activity showing an alertdialog.. when ok button is clicked i want to go to the activity of my app that was before on the screen or, if my app was not in front, come back to the window that user was showing.. this is my alertdialog

public class ActivityNotification extends Activity{
private String client,notifica;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    client = getIntent().getStringExtra("client");
    notifica = getIntent().getStringExtra("notifica");

    final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle("Notifica da "+client);
    alertDialog.setMessage(notifica);
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            alertDialog.cancel();
        }
    });
    alertDialog.setIcon(R.drawable.icon);
    alertDialog.show();
}
}

and this is the way i call this activity from a service

Notification notification = new Notification(R.drawable.icon, "Notifica da "+client, 10000);
    notification.flags |=Notification.FLAG_AUTO_CANCEL;
    CharSequence contentTitle = "Notifica da "+client;
    CharSequence contentText = notifica;
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    //Intent notificationIntent = new Intent(this,ActivityNotification.class);
    Intent notificationIntent = new Intent();
    notificationIntent.setClassName("package", "package.ActivityNotification");
    notificationIntent.putExtra("client",client);
    notificationIntent.putExtra("notifica",notifica);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,0);
    notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent);
    mManager.notify(id, notification);

what can i do? can u help me?

2 Answers 2

0

Sounds like you need to recover the history stack of the applications that currently on the phone. The ActivityManager can help you with this.

Ref:

http://developer.android.com/reference/android/app/ActivityManager.html

1
  • That is correct! But as LuxuryMode said you should really modularize your code if possible, it will make it that much easier to use!
    – JoxTraex
    Dec 23, 2011 at 2:38
0

You seem to have a ton of stuff going on in there just to start an activity from the service. Why can't you just do something like:

Intent intent = new Intent(getBaseContext(), SomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(intent);

?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.