You cannot finish an activity this way. An activity has to finish itself. Rather than set up your BroadcastReceiver in the manifest, have the activity register it via registerReceiver(), and you can then more easily finish the activity.
On Mon, Oct 17, 2011 at 6:38 AM, shashank <[email protected]> wrote: > Hey, > > Im tryin hard to finish an activity from my BroadcastReceiver... but > ending up in - java.lang.ClassCastException: > android.app.ReceiverRestrictedContext error. > > Here is my code snippet let me know wat can be done, > > public void onReceive(Context context, Intent intent) { > try { > if(intent.getAction().equalsIgnoreCase("alarm_call")){ > Intent newIntent = new Intent(); > > newIntent.setClass(context,com.wipro.icici_phase_1.login.Login.class); > newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); > context.startActivity(newIntent); > ((Activity)context).finish(); > } > } catch (Exception e) {} > } > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy _Android Programming Tutorials_ Version 4.0 Available! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

