大哥 你这报错信息呢?
FATAL EXCEPTION: main
后面的信息呢? 没有的话没法解决呀
还有下面这段代码能编译通过吗?
if (togglebutton.isChecked()) {
intent = new Intent();
intent.setAction("com.example.temp.MY_SERVICE");
startService(intent);
} else {
stopService(intent);
}
FATAL EXCEPTION: main
后面的信息呢? 没有的话没法解决呀
还有下面这段代码能编译通过吗?
if (togglebutton.isChecked()) {
intent = new Intent();
intent.setAction("com.example.temp.MY_SERVICE");
startService(intent);
} else {
stopService(intent);
}
解决方案 »
- 给gps定位activity 添加一个broadcastreciever 短信监听 如何实现??
- android读取各类文件
- 超级好的 android 音乐播放器 源码
- Settings源码 PreferenceScreen 跳转Activity问题
- SDK创建的600x1024分辨率模拟器打不开。。
- android发送彩信 带图片
- IPC(进程间通信),Remote Call(远程调用),IDL(接口描述语言)架构及其在BMP(BREW移动平台),Android中的应用浅析
- 从html源码中获取URL链接,在线等了
- java中如何实现传入的参数不同,产生的单例也不同
- 我的Android用不了为什么
- 十万加急,微信开发
- 请问什么版本管理工具好用?
Intent intent = new Intent(yourActivity.this,yourService.class);
错误信息如下
intent = new Intent();
intent.setAction("com.example.temp.MY_SERVICE");
startService(intent);方法二:
Intent intent = new Intent(MainActivity.this, MyService.class);
startService(intent);
AndroidManifest.xml
<service android:name="MyService">
<intent-filter >
<action android:name="com.example.temp.MY_SERVICE"/>
</intent-filter>
</service>MyService.java
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;
public class MyService extends Service {MainActivity.java
package com.example.temp;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;public class MainActivity extends Activity {
... ...
intent = new Intent();
intent.setAction("com.example.temp.MY_SERVICE");
startService(intent);