android - Starting services -


i've started android developing , have been reading services here. i've created service try start in activity, cannot work out why not show toast notifications.

i've got following activity:

package com.example;  import android.app.activity; import android.content.context; import android.content.intent; import android.os.bundle;  public class example extends activity {     /** called when activity first created. */     @override     public void oncreate(bundle savedinstancestate)     {         super.oncreate(savedinstancestate);         context context = getapplicationcontext();          intent intent = new intent(context, mservice.class);         startservice(intent);         setcontentview(r.layout.main);     } } 

and in manifest have this:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"   package="com.example"   android:versioncode="1"   android:versionname="1.0"> <application android:label="example" android:icon="@drawable/icon">     <activity android:name="example"               android:label="@string/app_name">         <intent-filter>             <action android:name="android.intent.action.main" />             <category android:name="android.intent.category.launcher" />         </intent-filter>     <service android:name=".mservice" />     </activity> </application> 

and service looks this:

package com.example;  import android.app.intentservice; import android.content.intent; import android.widget.toast;  public class mservice extends intentservice {  public mservice() {     super("mservice"); }  @override public int onstartcommand(intent intent, int flags, int startid) {     toast.maketext(this, "service starting", toast.length_short).show();     return super.onstartcommand(intent,flags,startid); }  @override protected void onhandleintent(intent intent) {     toast.maketext(this, "systems starting", toast.length_short).show(); } 

}

i know not mean override onstartcommand more testing exercise since tried without

try reversing order of lines within onstartcommand - assign super call int variable, pop toast return var. if doesn't work, it's preferred way of overriding methods.


Comments