-1

How to pass String From IntentService To Activity.

MyService.java

protected void onHandleIntent(Intent intent) {

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

Activity is same which is calling Service class.

Ravindra Kushwaha
  • 7,846
  • 14
  • 53
  • 103

2 Answers2

0

just simply goto inside onHandleIntent method and do some staffs like the code bellow

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);
}
Benjamin
  • 21
  • 2
  • @Bejamin: Actually My Activity is flickering When try Add code provided by u.. I want to Update same Activity from which i am Calling the service and also string is not getting passed –  Feb 04 '16 at 08:07
0

Use ResultReceiver class to send data from IntentService to Activity. Please refer this link. How to get results from an IntentService back into an Activity?

vishnuc156
  • 940
  • 12
  • 10