Someone requested the changes that fixed this issue so here they are:

public class MyReceiver extends BroadcastReceiver
{

        @Override
        public void onReceive(Context context, Intent intent)
        {
                try
                {

                        Intent iAlarm = new Intent( context,
MyActivity.class );
                        iAlarm.addFlags(Intent.FLAG_FROM_BACKGROUND);
                        iAlarm.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);   // 
Added
                        iAlarm.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        context.startActivity(iAlarm);
                }
                catch( Exception e )
                {
                        .....
                }
        }

}


Then in my manifest:

To the activity tag:   android:launchMode="singleTask"


Seems to work like a charm now!


On Dec 4, 7:40 am, csyperski <[email protected]> wrote:
> Thanks,
>
> Changing android:launchMode worked, I still needed
> Intent.FLAG_ACTIVITY_NEW_TASK or the activity wouldn't start if it
> wan't running.  Thanks again!
>
> On Dec 3, 6:41 pm, Farproc <[email protected]> wrote:
>
> > Clues:
>
> > 1. android:launchMode attribute of you Activity.
> > 2. Intent.FLAG_ACTIVITY_NEW_TASK should not be set if you do not want
> > to see multi-instances.
>
> > On 12月4日, 上午8时32分, csyperski <[email protected]> wrote:
>
> > > I have a problem with starting an intent from a BroadcastReceiver,
> > > where everytime onReceive() is called from the BroadcastReceiver it
> > > starts an intent which loads an activity.  My problem is every time it
> > > seems to start a new instance of the Acitivty (even if it is already
> > > running) and I would like it to be a singleton.  The problem this
> > > causes is that after a few calls of onReceive(), if the user hits the
> > > back button on the app, they are presented with what sees to be the
> > > same activity multiple times.
>
> > > Here is the basics of what I am doing:
>
> > > public class MyReceiver extends BroadcastReceiver
> > > {
>
> > >         @Override
> > >         public void onReceive(Context context, Intent intent)
> > >         {
> > >                 try
> > >                 {
>
> > >                         Intent iAlarm = new Intent( context, 
> > > MyActivity.class );
> > >                         iAlarm.addFlags(Intent.FLAG_FROM_BACKGROUND);
> > >                         iAlarm.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
> > >                         context.startActivity(iAlarm);
> > >                 }
> > >                 catch( Exception e )
> > >                 {
> > >                         .....
> > >                 }
> > >         }
>
> > > }
>
> > > Any pointers would be appreciated, and thanks for your help in
> > > advance.
>
> > > Thanks,
> > > Chuck

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

Reply via email to