【发布时间】:2015-02-12 20:01:55
【问题描述】:
如何从 non-activity 类启动 BroadcastReceiver 或 IntentService
我的意思是发送意图并运行 BroadcastService 或 IntentService
即:
我有课:
public class NumberOne{
@Override
public int functionOne(){
int i = 1 + 4;
if(/*something is true*/){
Intent intent = new Intent(this,intetServiceOne.class);
intent.putExtra("id","path");
context.startService(intent);
}
else {/*continue*/
}
return i;
}
//other functions
}
如果 functionOne 中的条件为真,则启动 IntentService
public class IntentServiceClassOne extends IntentService {
public IntentServiceClassOne () {
super("IntentServiceClassOne ");
}
@Override
protected void onHandleIntent(Intent intent) {
String data = intent.getStringExtra("id");
Log.d("dataIs: ", data);
}
//more functions what to do
}
它不依赖于它是 IntentService 还是 BroadcastReceiver 谢谢
【问题讨论】:
标签: android class broadcastreceiver android-intentservice