I am using service in my program where i have MainActivity.java and MyService.java in Mainactivity i called intent as
public void onClick(View src)
{
switch (src.getId()) {
case R.id.ButtonStart:
Log.d(TAG, "onClick: starting service");
startService(new Intent(this,com.example.MyService1.class));
brea开发者_JAVA百科k;
case R.id.ButtonStop:
Log.d(TAG,"onClick: stopping service");
stopService(new Intent(this,com.example.MyService1.class));
break;
}
}
but i am getting error on Log.d that "WARN/ActivityManager(68): Unable to start service Intent { cmp=com.example/.MyService1 }: not found" please tell me solution.
You are using file MyService.java
and starting service like this:
startService(new Intent(this,com.example.MyService1.class));
Now insure that why you are using com.example.MyService1.class
instead of MyService
here?
Just simply use like this: startService(new Intent(this,MyService.class));
Make sure you declared your service in the AndroidManifest.xml file.
<service android:name="com.example.MyService1"/>
精彩评论