Thank you so much, that was it! Regards, Simon
On Sun, Jun 5, 2011 at 7:41 PM, Kostya Vasilyev <[email protected]> wrote: > The offending line is this: > > public myService(String name) { > super(name); > setIntentRedelivery(true); > } > > Android instantiates components (services, activities) using the > component's default constructor. > > An explicit non-default constructor like the above prevents the compiler > from generating the default one, and it can't use any constructors with > arguments because it has no way to know what they values would be. > > Then Android fails to instantiate your service. > > Change the constructor to: > > public myService(/* no arguments */) { > super("some name string"); > setIntentRedelivery(true); > } > > The reason IntentService and WakefulIntentService have a constructor with a > string parameter is they are meant to be subclassed. And that's something > you could consider as well to improve maintainability. > > -- Kostya > > 2011/6/5 Simon Platten <[email protected]> > >> Earlier I posted a question regarding a problem I'm having with my >> BroadcastReceiver and onReceive method. I found that the logic in onReceive >> would sometimes crash and I couldn't find an explanation why, one road I >> went down was to try creating a thread in onReceive, whilst this was better, >> it didn't cure the problem altogether. >> >> I then got a response from "Mark Murphy", pointing me in the direction of >> the CWAC demo, which I am looking at, but having tried to implement the same >> techniques used in the demo, my intent fails to launch with an error in the >> logger "no init"...I've compared my code to the CWAC demo and cannot see >> what I'm missing. >> >> In summary, my application starts off with an activity that gets input >> from the user, it then installs a repeating alarm, the alarm works well and >> I can see that the BroadcastReceiver onRecieve method is called reliably, >> however sometimes there is a crash in the onReceive method, it continues to >> be scheduled at the specified interval, but fails to work from this point >> on. All my efforts to find out why have failed. >> >> I am changing the wallpaper via the WallpaperManager in the onReceive. >> Now I am trying to implement the same technique used byt eh CWAV demo, but >> it fails. Here is my Receiver: >> >> [code] >> public class myReciever extends BroadcastReceiver { >> @Override >> public void onReceive(Context context, Intent intent) { >> myService.sendWakefulWork( context ); >> } >> } >> [/code] >> >> Here is the myService class: >> >> [code] >> public class myService extends IntentService { >> private static final String LOCK_NAME_STATIC = "myService"; >> >> private static volatile PowerManager.WakeLock m_lockStatic = null; >> >> synchronized private static PowerManager.WakeLock getLock(Context >> context) { >> if( m_lockStatic == null ) { >> PowerManager mgr = >> (PowerManager)context.getSystemService(Context.POWER_SERVICE); >> m_lockStatic = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, >> LOCK_NAME_STATIC); >> m_lockStatic.setReferenceCounted(true); >> } >> return m_lockStatic; >> } >> >> public static void sendWakefulWork(Context context, Intent i) { >> getLock(context).acquire(); >> context.startService( i ); >> } >> >> public static void sendWakefulWork( Context ctxt ) { >> Intent intent = new Intent( ctxt, myService.class ); >> sendWakefulWork( ctxt, intent ); >> } >> >> public myService(String name) { >> super(name); >> setIntentRedelivery(true); >> } >> >> @Override >> public int onStartCommand(Intent intent, int flags, int startId) { >> if ( (flags & START_FLAG_REDELIVERY) != 0 ) { // if crash >> restart... >> getLock(this).acquire(); // ...then quick >> grab the lock >> } >> super.onStartCommand(intent, flags, startId); >> return START_REDELIVER_INTENT; >> } >> >> @Override >> final protected void onHandleIntent(Intent intent) { >> try { >> doWakefulWork(intent); >> } finally { >> getLock(this).release(); >> } >> } >> >> private void doWakefulWork( Intent intent ) { >> // ... Do something, but it never gets here ! >> >> } >> } >> [/code] >> >> The manifest file: >> [code] >> <?xml version="1.0" encoding="utf-8"?> >> <manifest xmlns:android="http://schemas.android.com/apk/res/android" >> package="com.myPackage" >> android:versionName="1.1" android:versionCode="1"> >> <application android:icon="@drawable/icon" >> android:label="@string/app_name"> >> <activity android:name=".awrActivity" >> android:label="@string/app_name"> >> <intent-filter> >> <action android:name="android.intent.action.MAIN" /> >> <category android:name="android.intent.category.LAUNCHER" >> /> >> </intent-filter> >> </activity> >> <receiver android:name="uk.co.cantley.avasig.myReciever" /> >> <service android:name="uk.co.cantley.avasig.myService" /> >> </application> >> <uses-sdk android:minSdkVersion="7" /> >> <uses-permission android:name="android.permission.SET_WALLPAPER"/> >> <uses-permission android:name="android.permission.WAKE_LOCK"/> >> <supports-screens android:largeScreens="true" >> android:normalScreens="true" >> android:smallScreens="true" >> android:resizeable="false" >> android:anyDensity="true"/> >> </manifest> >> [/code] >> >> Thank you, >> Simon >> >> -- >> 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 -- 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

