I am trying to develop a small app that starts on boot for a class. I tried to follow the instructions http://www.androidcompetencycenter.com/2009/06/start-service-at-boot/ but I am having problems.
Manifest
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver android:name="MyStartupIntentReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
<service android:name="MyService">
<intent-filter>
<action android:name="com.startup.MyService" />
</intent-filter>
</service>
Receiver
public class Startup extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Intent serviceIntent = new Intent();
serviceIntent.setAction("com.startup.MyService");
context.startService(serviceIntent);
}
}
Service
public class MyService extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
public void onCreate() {
super.onCreate();
Toast.makeText(this, "Service Created", Toast.LENGTH_LONG).show();
}
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
while (true)
{
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
I am testing it by using eclipse to deploy the app to the emulator, closing the emulator, and then opening the same emulator instance via the Android SDK and ADV Manager. I also have the dev option that displays running processes turned on. When I do this, I do not see either anything relevant in the process list and I do not see the messages pop up. What am I doing wrong?