android 通过扩展 intentservice 中的 intent 获取变量 activity
android getting a variable through intent inside an extended intentservice activity
标题不言自明,我该怎么做?
我已经尝试过经典的 Intent 方法,但是 getIntent() 部分在我的 activity extends IntentService..
中不起作用
您不需要从 IntentService 调用 getIntent()
。
当您的 IntentService 启动 运行(使用 onHandleIntent()
)时,您将获得作为参数的意图。然后您可以使用 getStringExtra()
正常阅读附加内容。检查下面的代码:
@Override
protected void onHandleIntent(Intent intent) {
String username = intent.getStringExtra("key_1");
String password = intent.getStringExtra("key_2");
// Code here ...
}
查看此 link 了解更多信息:Using putExtra to pass values to intent service
标题不言自明,我该怎么做?
我已经尝试过经典的 Intent 方法,但是 getIntent() 部分在我的 activity extends IntentService..
中不起作用您不需要从 IntentService 调用 getIntent()
。
当您的 IntentService 启动 运行(使用 onHandleIntent()
)时,您将获得作为参数的意图。然后您可以使用 getStringExtra()
正常阅读附加内容。检查下面的代码:
@Override
protected void onHandleIntent(Intent intent) {
String username = intent.getStringExtra("key_1");
String password = intent.getStringExtra("key_2");
// Code here ...
}
查看此 link 了解更多信息:Using putExtra to pass values to intent service