HI Everyone, I'm having trouble successfully launching my activity properly form a Notification or Widget. Firstly let me explain how I am handling my activities (for all I know it could be the completely wrong way to handle activities, in which case I'll change it, but it works for the most part)
I have a Main.class Activity, that doesn't have any layout associated with it. It is what is launched when the application is launched. In the onCreate method (which I have overridden), I read from SharedPreferences to determine if the user is logged in or not. If they aren't logged in, Main will then use startActivityForResult() to launch Login.class. If they are logged in, it will launch (for example) Details.class. In both Login.class and Details.class, I have overridden onBackPressed() which uses setResult(-1) and then finish()'s the activity. I have overridden the onReceive() method in Main.class, and if it recieves -1, it will finish() that activity as well. This makes the back button work as expected (you shouldn't be able to use the back button to get from Details.class to Login.class, as there's a dedicated logout button for that. Having the back button log the person out isn't what I want.) Firstly, if this is the completely wrong way to launch the UI and handle activities, let me know (I suspect it may be,) and I'll change it so that Login.class is what get's launched, and it will launch Details.class if the user is already logged in. The problem that I have is this: if I start the Main.class activity from either a Widget or Notificaton using PendingIntent like so: Intent intent = new Intent ( context , Main.class ); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); It will launch it as expected. But it will launch another instance. If I press the back button from the newly launched Activity, it will close the current Activity, but it will then display the old Activity (that may not have been killed by Android yet) that has been brought to the front. So it goes something like this: Details screen displayed -> Back Pressed -> Old details screen displayed -> Back pressed -> Home is displayed (or whatever activity was running) Obviously it looks poorly coded if pressing back doesn't really do anything, you have to do it twice (if the user keeps launching from the widget, it can be how ever many times they have launched it + 1 ). I'm guessing it's partly because it is poorly coded, but I don't know what I need to do to fix it. Does anyone have any suggestions on the best way to solve this? I've looked into bringing the current activity to the front, but I can't seem to find any way of doing that. Thanks, Josh. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en