首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将数据从意图服务传递到活动

将数据从意图服务传递到活动
EN

Stack Overflow用户
提问于 2014-09-19 07:41:00
回答 3查看 5.8K关注 0票数 5

我有一个广播接收器正在呼叫intentservice,我想将intentservice中接收到的数据发送到一个activity.String s=extras.getString(“通知”).I想将接收到的字符串发送到一个新的活动

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-09-19 09:29:01

代码语言:javascript
复制
@Override
protected void onHandleIntent(Intent arg0) {
   Intent dialogIntent = new Intent(getBaseContext(), myActivity.class);
    dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     dialogIntent.putExtra("value", extras.getString("Notice"));
     getApplication().startActivity(dialogIntent);
}   
票数 1
EN

Stack Overflow用户

发布于 2014-09-19 07:45:26

代码语言:javascript
复制
public class YourIntentService extends IntentService {

    @Override
    protected void onHandleIntent(Intent arg0) {
        // TODO Auto-generated method stub
        Intent intent = new Intent(this, YourNewActivity.class);
        intent.putExtra("YourStringKey", "yourString");
        startActivity(intent);
    }

    public YourIntentService() {
        super("YourIntentService");
    }

}

尝尝这个。抱歉误会了。

票数 0
EN

Stack Overflow用户

发布于 2014-09-19 08:00:27

代码语言:javascript
复制
public class MyIntentService extends IntentService {

public  MyIntentService() {
    super(" MyIntentService");

}

@Override
protected void onHandleIntent(Intent arg0) {
        String s=arg0.getExtras.getString("Notice")
        Intent i = new Intent(this, yourActivity.class);
        i.putExtra("Notice",s);
        getApplication().startActivity(i);
}   

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25928804

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档