My UpdateService in MoonClockWidget won't restart.

Put your problem here if it does not fit any of the other categories.

My UpdateService in MoonClockWidget won't restart.

Postby jsemler » Thu Apr 29, 2010 2:20 am

It will restart the normal way, after about 30 minutes.

But after terminating the service via "Advanced Task Killer", I get a message that the service will be restarted after XXXXX ms. Nevers restarts in XXXXX ms as the system logs implied it will. What am I missing?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package net.jsemler.astronomy.moonclock;
  3.  
  4.  
  5.  
  6. import java.util.Timer;
  7.  
  8. ...
  9.  
  10. ...
  11.  
  12. ...
  13.  
  14.  
  15.  
  16. public class MoonClockWidget extends AppWidgetProvider {
  17.  
  18.     ...
  19.  
  20.     ...
  21.  
  22.     ...
  23.  
  24.  
  25.  
  26.     @Override
  27.  
  28.     public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
  29.  
  30.         context.startService(new Intent(context, UpdateService.class));
  31.  
  32.         super.onUpdate(context, appWidgetManager, appWidgetIds);
  33.  
  34.     }
  35.  
  36.        
  37.  
  38.     static public class UpdateService extends Service {
  39.  
  40.         ...
  41.  
  42.         ...
  43.  
  44.         ...
  45.  
  46.  
  47.  
  48.         @Override
  49.  
  50.         public int onStartCommand(Intent intent, int flags, int startId) {
  51.  
  52.             ...
  53.  
  54.             ...
  55.  
  56.             ...
  57.  
  58.             return START_REDELIVER_INTENT;
  59.  
  60.         }
  61.  
  62.  
  63.  
  64.         ...
  65.  
  66.         ...
  67.  
  68.         ...
  69.  
  70.     }
  71.  
  72. }
  73.  
  74.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


The description for START_REDELIVER_INTENT is as follows:

public static final int START_REDELIVER_INTENT
Since: API Level 5

Constant to return from onStartCommand(Intent, int, int): if this service's process is killed while it is started (after returning from onStartCommand(Intent, int, int)), then it will be scheduled for a restart and the last delivered Intent re-delivered to it again via onStartCommand(Intent, int, int). This Intent will remain scheduled for redelivery until the service calls stopSelf(int) with the start ID provided to onStartCommand(Intent, int, int). The service will not receive a onStartCommand(Intent, int, int) call with a null Intent because it will will only be re-started if it is not finished processing all Intents sent to it (and any such pending events will be delivered at the point of restart).
Constant Value: 3 (0x00000003)


I intend for my service to always run.

Here's what I believe are the relevant portion of my manifest file.

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.         <receiver
  3.  
  4.             android:name=".MoonClockWidget">
  5.  
  6.            
  7.  
  8.                 <intent-filter>
  9.  
  10.                 <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
  11.  
  12.                     </intent-filter>
  13.  
  14.                    
  15.  
  16.                     <meta-data
  17.  
  18.                             android:name="android.appwidget.provider"
  19.  
  20.                android:resource="@xml/moonclockwidget_info" />
  21.  
  22.         </receiver>
  23.  
  24.  
  25.  
  26.         <service android:name=".MoonClockWidget$UpdateService" />
  27.  
  28.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


What do I need to do to fix it so that the system really does restart the service if it gets killed?
Attachments
MoonClockWidget.java
The complete source
(4.89 KiB) Downloaded 53 times
jsemler
Junior Developer
Junior Developer
 
Posts: 24
Joined: Sun Apr 18, 2010 3:53 pm

Top

Postby jsemler » Thu Apr 29, 2010 11:09 pm

Let me rephrase my concern...

My concern is about users killing the Moon Clock activity launched from main. I really don't care if the user wants to shut down the service (when they knowingly do it), but novice users running "Advanced Task Killer Free" or similar programs could kill the Moon Clock Updater service without realizing that the Widgets remote views won't update any more (may be dead for as long as 30 minutes).

I can work around this problem if I don't allow the activity it to be launched manually. Widgets, activities without the launch-able intent, and services do not get listed under "Advanced Task Killer Free" for defaults settings.

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <manifest
  5.  
  6.    xmlns:android="http://schemas.android.com/apk/res/android"
  7.  
  8.    package="net.jsemler.astronomy.moonclock"
  9.  
  10.    android:versionCode="1"
  11.  
  12.    android:versionName="1.0">
  13.  
  14.      
  15.  
  16.     <uses-permission android:name="android.permission.INTERNET" />
  17.  
  18.     <uses-sdk android:minSdkVersion="6" />
  19.  
  20.  
  21.  
  22.     <application
  23.  
  24.        android:icon="@drawable/moonclock_icon"
  25.  
  26.        android:label="Moon Clock">
  27.  
  28.         <uses-library android:name="com.google.android.maps" />
  29.  
  30.  
  31.  
  32.         <activity
  33.  
  34.            android:name=".MoonClock"
  35.  
  36.            android:configChanges="orientation|keyboardHidden"
  37.  
  38.            android:label="@string/moonClockTitle">
  39.  
  40. <!--
  41.  
  42.            <intent-filter>
  43.  
  44.                <action android:name="android.intent.action.MAIN" />
  45.  
  46.                <category android:name="android.intent.category.LAUNCHER" />
  47.  
  48.            </intent-filter>
  49.  
  50. -->
  51.  
  52.         </activity>
  53.  
  54.  
  55.  
  56.         <activity
  57.  
  58.            android:name=".googlemap.GoogleMap"
  59.  
  60.            android:label="@string/googleMapTitle">
  61.  
  62.         </activity>
  63.  
  64.  
  65.  
  66.         <receiver
  67.  
  68.            android:name=".MoonClockWidget" >
  69.  
  70.            
  71.  
  72.             <intent-filter>
  73.  
  74.                 <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
  75.  
  76.             </intent-filter>
  77.  
  78.                    
  79.  
  80.             <meta-data
  81.  
  82.                android:name="android.appwidget.provider"
  83.  
  84.                android:resource="@xml/moonclockwidget_info" />
  85.  
  86.         </receiver>
  87.  
  88.  
  89.  
  90.         <service
  91.  
  92.            android:name=".UpdateService"
  93.  
  94.            android:label="Moon Clock Updater" />
  95.  
  96.  
  97.  
  98.     </application>
  99.  
  100.  
  101.  
  102. </manifest>
  103.  
  104.  
Parsed in 0.005 seconds, using GeSHi 1.0.8.4


Is there a way to separate launch-able activities and services so that they don't get killed as a group when the user kills the activity?

The widget starts the Moon Clock activity when the user taps on it. I just would like to give the user the ability to launch from home screen without having to install the Moon Clock widget.
jsemler
Junior Developer
Junior Developer
 
Posts: 24
Joined: Sun Apr 18, 2010 3:53 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 28 guests