Ok. So I took a look at my code. This is what you need to do.

1) Create a new class that extends BroadcastReceiver
        inside this class on the onReceive method should resemble this:
                public static final String ACTION_ALERT_USER =
"xxx.xxx.ACTION_ALERT_USER";  The xxx should be filled in with your package
name that shows up under the source folder
        @Override
        public void onReceive(Context context, Intent intent) {
                PowerManager pm =
(PowerManager)context.getSystemService(Context.POWER_SERVICE);
                PowerManager.WakeLock wl =
pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP, "Severe_Weather_Alert_Wake");
                wl.acquire(30000);
                
                
                Intent startIntent = new Intent(context,
TheActivityYouWantToCall.class);
                
                startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                
                context.startActivity(startIntent);
                
        }

2) Now in your service you send a broadcast for this receiver
        final String Alert_User = " xxx.xxx.ACTION_ALERT_USER ";  Exact same
as above
                                
                                Intent alert = new Intent();
                                alert.setAction(Alert_User);
                                this.sendBroadcast(alert);  




3) You will then need to register the broadcast receiver,service and
activity in the manifest

        You can register a receiver in the manifest like this:

        <receiver android:name=".NameOfYourReceiverClass">
        <intent-filter>
        <action android:name="xxx.xxx.ACTION_ALERT_USER"></action> 
        </intent-filter>
        </receiver>

This is how I have done it. I couldn't tell you if this is the proper or
most efficent way but it seems to work for me. hope this helps

Tommy


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Kartik Bansal
Sent: Friday, November 19, 2010 1:53 PM
To: Android Developers
Subject: [android-developers] Re: calling activity from service

thanks a lot.. it would be gr8 if u could share the code snippet.. i
am all so confused with intents..

On Nov 19, 11:46 pm, "Tommy" <[email protected]> wrote:
> You should be able to do it the same way you would call it from any other
> activity. Only before you call startActivity be sure to set the
> FLAG_ACTIVITY_NEW_TASK setting like below:
>
> Intent beginActivity //so on
> beginActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
> startActivity(beginActivity);
>
> I think thats how I did it in my code. I am not infort of that PC right
now
> to confirm though. Hopefully this will help.
>
> Tommy
>
>
>
>
>
>
>
> -----Original Message-----
> From: [email protected]
>
> [mailto:[email protected]] On Behalf Of Kartik Bansal
> Sent: Friday, November 19, 2010 1:32 PM
> To: Android Developers
> Subject: [android-developers] calling activity from service
>
> hi..
>
> i am writing an app in which i need a background service to call an
> activity and show some result..
>
> pls share some example..
>
> thnx a lot..
> kartik..
>
> --
> 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
athttp://groups.google.com/group/android-developers?hl=en

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

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