开发者

How to pass String value from Service to Activity in android?

开发者 https://www.devze.com 2023-03-13 10:53 出处:网络
In my small android application I created a Service to receive some string from web server an开发者_JS百科d i want to pass that string to my activity and display that in textview

In my small android application I created a Service to receive some string from web server an开发者_JS百科d i want to pass that string to my activity and display that in textview

I tried this Code:

Intent intent = new Intent(this, SecondActivity.class);
Bundle b = new Bundle();  

b.putString("key", ITEM);  
intent.putExtras(b);
startActivity(intent);

// In Activity

Bundle b = this.getIntent().getExtras();
String i = b.getString("key");

But it always forcefully closing the application

Please any one help me because i wasted one week for this

Thanks in Advance


Is this a completley new activity ? or are you trying to relaunch the default activity ?

I suggest to take a look at the Remote messenger sample.

http://developer.android.com/reference/android/app/Service.html#RemoteMessengerServiceSample

This pretty much covers your needs to comunicate a service with an activity.

0

精彩评论

暂无评论...
验证码 换一张
取 消