如果我打电话
Intent intent = new Intent(ReadingActivity.this, AdService.class);
startService(intent);
在 MyActivity
类的 onCreate
方法中,如何从 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);
}
最佳答案
how do I get access to MyActivity.this from inside the onHandleIntent method of the IntentService class
你不知道。
将 createAd()
移动到 Activity 中。如果时间有问题,请使用 AsyncTask
而不是 IntentService
。
IntentService
主要用于您希望工作与任何 Activity 分离的情况(例如,即使用户离开您的 UI,文件下载也应该继续继续做其他事情)。
关于Android:如何在 IntentService 中获取调用 Activity 的上下文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11727856/