I make a small change to the sample Plusminus has delivered in the post, since I want to start a background service instead of an activity on System/Emulator startup.
So I replace the LaunchOnStartup activity by a service “NotifyingService”, and change the manifest to this one:
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="cienet.cl">
- <application android:icon="@drawable/icon">
- <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="NotifyingService">
- </service></application>
- </manifest>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
Then in the onCreate method of MyStartupIntentReceiver, I replace the startActivity by startService:
Using java Syntax Highlighting
- public void onReceiveIntent(Context context, Intent intent) {
- /* Create intent which will finally start the Main-Activity. */
- Intent myStarterIntent = new Intent(context, NotifyingService.class);
- /* Set the Launch-Flag to the Intent. */
- myStarterIntent.setLaunchFlags(Intent.NEW_TASK_LAUNCH);
- /* Send the Intent to the OS. */
- // context.startActivity(myStarterIntent);
- context.startService(myStarterIntent, null);
- }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
But, I get an error msg said there is no activity. So, can’t I start a service without an activity?
Best wishes,
Rader

