如何将String
从IntentService
传递到Activity
。
MyService.java
protected void onHandleIntent(Intent intent) {
String abc ="XYZ"; // pass this string to Activity class
}
活动与调用服务类相同。
答案 0 :(得分:0)
只需简单地转到onHandleIntent方法内部,然后像下面的代码那样做一些人员
protected void onHandleIntent(Intent intent){
String abc ="XYZ"; // pass this string to Activity class
// Open a new activity called in my case Activity1
Intent intent = new Intent(this, Activity1.class);
// Pass data to the new activity
intent.putExtra("message", abc);
//then finally start the activity
startActivity(intent);
}
答案 1 :(得分:0)
使用ResultReceiver类将数据从IntentService发送到Activity。 请参阅此链接。 How to get results from an IntentService back into an Activity?