MyService.java
public class MyService extends Service {@OverrIDepublic IBinder onBind(Intent intent) { return null;}public static boolean isinstanceCreated() { return instance != null; }@OverrIDepublic voID onCreate() { Toast.makeText(this,"My Service Created",Toast.LENGTH_LONG).show(); Log.d(TAG,"onCreate"); instance = this;}@OverrIDepublic voID onDestroy() { Toast.makeText(this,"My Service Stopped","onDestroy"); instance = null;}@OverrIDepublic voID onStart(Intent intent,int startID) { Toast.makeText(getBaseContext(),"Service started",Toast.LENGTH_SHORT).show(); }}
从SampleService.java启动服务
public class SampleService extends Activity{@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.grID_activity); Intent myintent =new Intent(SampleService.this,MyService.this);//Error show here.. startService(myintent); } }
清单文件中初始化的服务.
<service androID:enabled="true" androID:name="com.MyApp.MyService" />
帮我解决错误.
解决方法 不是Service.this你必须通过课程所以这样改变..
Intent myintent =new Intent(SampleService.this,MyService.Class);总结
以上是内存溢出为你收集整理的错误:在android中启动服务时未定义的意图构造函数全部内容,希望文章能够帮你解决错误:在android中启动服务时未定义的意图构造函数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)