相关疑难解决方法(0)

在服务中获取上下文

有没有可靠的方法来获得Context一个Service?

我想注册广播接收器,ACTION_PHONE_STATE_CHANGED但我不需要我的应用程序总是得到这些信息,所以我不把它放在Manifest.

但是,当我需要这些信息时,我不能让GC杀死广播接收器,因此我正在注册广播接收器Service.

因此,我需要一个Context来打电话registerReceiver().当我不再需要时,ACTION_PHONE_STATE_CHANGED我取消注册它.

有小费吗?

android broadcastreceiver android-service

268
推荐指数
6
解决办法
12万
查看次数

Android:如何在IntentService中获取调用活动的上下文?

如果我打电话

Intent intent = new Intent(ReadingActivity.this, AdService.class);
startService(intent);       
Run Code Online (Sandbox Code Playgroud)

从类的onCreate方法中MyActivity,我如何MyActivity.this从类的onHandleIntent()方法内部访问IntentService

@Override
protected void onHandleIntent(Intent arg0) {
    // TODO Auto-generated method stub
    ((BookLib) getApplication()).createAd(I need to pass the calling activities context here);
}
Run Code Online (Sandbox Code Playgroud)

android intentservice

3
推荐指数
1
解决办法
1万
查看次数