如何将String从IntentService传递给Activity

时间:2016-02-03 13:24:44

标签: android android-intent android-activity intentservice

如何将StringIntentService传递到Activity

MyService.java

protected void onHandleIntent(Intent intent) {

   String abc ="XYZ"; // pass this string to Activity class
}

活动与调用服务类相同。

2 个答案:

答案 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?