AutoStart

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

AutoStart

Postby nisha » Tue Apr 01, 2008 7:01 am

Hi All,

I got how to run services in backgroud and foreground.. If anybody knows how to autostart any service please reply me... If you have sample code plz give me...
nisha
Experienced Developer
Experienced Developer
 
Posts: 80
Joined: Fri Feb 15, 2008 7:52 am

Top

Postby ollie » Wed Apr 02, 2008 6:31 am

1.when the OS starts, it will send a Standard Broadcast Action named android.intent.action.BOOT_COMPLETED.

2.construct a class extended from IntentReceiver to catch the action, and override its abstract method onReceiveIntent(Context context, Intent intent), where you can put your start service code in.

3.in AndroidManifest.xml, you should add tag <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission> to get the permission of android.intent.action.BOOT_COMPLETED. In additon, you should add tag
<action android:name="android.intent.action.BOOT_COMPLETED" /> in the <intent-filter> of your IntentReceiver class.

code example:
xml:
Code: Select all
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
<receiver android:name=".OlympicsReceiver" android:label="@string/app_name">
    <intent-filter>
       <action android:name="android.intent.action.BOOT_COMPLETED" />
       <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</receiver>

java:

Code: Select all
public class OlympicsReceiver extends IntentReceiver
{
    /* the intent source*/
    static final String ACTION = "android.intent.action.BOOT_COMPLETED";
       
    public void onReceiveIntent(Context context, Intent intent)
    {
        if (intent.getAction().equals(ACTION))
        {
                  context.startService(new Intent(context,
                       OlympicsService.class), null);//start my your service here
             Toast.makeText(context, "OlympicsReminder service has started!",                      Toast.LENGTH_LONG).show();
        }
    }
}
ollie
Freshman
Freshman
 
Posts: 4
Joined: Tue Mar 25, 2008 1:41 pm

Postby nisha » Thu Apr 03, 2008 7:37 am

Hi,

Thank you...


regards,
nisha
nisha
Experienced Developer
Experienced Developer
 
Posts: 80
Joined: Fri Feb 15, 2008 7:52 am

Postby caldis » Mon Dec 08, 2008 1:10 pm

The IntentReceiver is no longer in the SDK. Can somebody point me to an updated howto/tutorial on services and autostart?

The new way is the BroadcastReceiver but it needs to be registered in the main activity. But since I want to autostart a service there is no main activity.

Help would be much appreciated.
Thanks

Problem solved:
No autostart is required since the AlarmManager will do the recurring "autostart"
Thanks
caldis
Freshman
Freshman
 
Posts: 7
Joined: Mon Dec 08, 2008 1:07 pm

Re: AutoStart

Postby jagtap.jj1 » Mon Mar 30, 2009 9:38 am

Hello nisha
will you help me for running services in background, if do u sample tut provide me. I read the concept of "service component of Android" in Android docs, but I don't have its implementation demo.

thank you
java-android developer
User avatar
jagtap.jj1
Senior Developer
Senior Developer
 
Posts: 124
Joined: Fri Aug 22, 2008 11:52 am
Location: India(Mumbai)

Postby rahulp » Wed Apr 08, 2009 6:54 am

hi all....
i am developing a chat application.. i am usin broadcast receiver to recieve SMS. but now i want to send it to the class where i am displaying hte content of the sms.
can anyone please tell me how to send a message from broad cast reciever classs to my activity class.
i tried starting a new activity. but tat creates a new activity every time i recieve a new sms.


thanks
rahul phadnis
rahulp
Developer
Developer
 
Posts: 30
Joined: Thu Feb 19, 2009 12:52 pm

Top

Return to General

Who is online

Users browsing this forum: No registered users and 6 guests