Android service not starting, no idea why -
i'm trying run thread starting service, won't start. won't log.
this inner service class. service class creates new background thread , starts it. backgroundthread , service class both innerclasses can reach variables.
public class myservice extends service { private backgroundthread background; @override public ibinder onbind(intent intent) { return null; } @override public void oncreate() { super.oncreate(); toast.maketext(this, "my service created", toast.length_long).show(); log.d(tag, "oncreate"); background = new backgroundthread(); } @override public void ondestroy() { super.ondestroy(); toast.maketext(this, "my service stopped", toast.length_long).show(); log.d(tag, "ondestroy"); } public int onstartcommand(intent intent, int flags, int startid) { super.onstartcommand(intent, startid, startid); toast.maketext(this, "my service started", toast.length_long).show(); log.d(tag, "onstart"); background.start(); return startid; } }
i'm starting service in mainactivity this:
startservice(new intent(this, myservice.class));
and manifest:
<application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.example.antioversleepapp.mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name="com.example.antioversleepapp.settingsactivity" android:label="@string/title_activity_settings" > </activity> <activity android:name="com.example.antioversleepapp.infoactivity" android:label="@string/title_activity_info" > </activity> <service android:enabled="true" android:name="com.example.antioversleepapp.myservice" /> </application>
please me out
this inner service class
that not possible. either needs static inner class (in case, <service>
element needs changing) or needs separate public class.
the backgroundthread , service class both innerclasses can reach variables.
i not see "variables" service needs "reach". moreover, impossible android create instance of inner class, since not have instance of outer class.
Comments
Post a Comment