开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜