如何从一个Intent服务消息发送到一个活动 [英] How to send a message from an Intent Service to an activity

查看:303
本文介绍了如何从一个Intent服务消息发送到一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我有了一个进度对话框的活动,我将消息发送到一个Intent加载所有来自Internet的数据,而不在应用程序中的任何打嗝。但是,我能够将消息发送到服务,但我无法发送邮件到活动中。 怎么办?

Basically, i have an activity that has a progress dialog, i'm sending a message to an Intent to load all the data from the internet without any hiccup in the application. However, i was able to send a message to the service but i wasn't able to resend the message to the activity. What to do?

下面就是我发短信给服务:

Here's how i send message to the service:

final Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {

    }
};
final Intent intent = new Intent(this, FillingDatabase.class);
final Messenger messenger = new Messenger(handler);
intent.putExtra("messenger", messenger);
startService(intent);

这就是我如何接受她从服务消息:

And here's how i recieve the message from the service:

messenger = (Messenger) intent.getParcelableExtra("messenger");
        message = Message.obtain(null, 1234);
            messenger.send(message);

不过,我不是能够知道如何才能收到该邮件中的活动,有人可以解释的方法呢? 谢谢!

But i wasnt able to know how to recieve that message in an activity, can someone explain the approach? Thank you!

推荐答案

试用如下:

  private Handler handler = new Handler() 
{
    public void handleMessage(Message message) 
    {
       final Intent intent = new Intent(this, FillingDatabase.class);
       final Messenger messenger = new Messenger(handler);
       intent.putExtra("messenger", messenger);
       startService(intent);
    };
};

这篇关于如何从一个Intent服务消息发送到一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆