我怎样才能启动片段广播接收器 [英] How can I launch fragment in broadcast receiver

查看:134
本文介绍了我怎样才能启动片段广播接收器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用广播接收器,启动/午餐片段 例如 : 如果我需要为启动/ luanch 活动,我可以使用意向

How can I use broadcast receiver to start/lunch fragment for example : if I need to start/luanch activity , I can use intent :

public void onReceive(final Context context, Intent intent) {

    this.context = context;
    this.intent = intent;

    try {
        Bundle bundle = intent.getExtras();

        int messageID = bundle.getInt("id");

        intent = new Intent(context, GetAlarm.class);

        intent.putExtra("id",messageID);

        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);

    } catch (Exception e) {
        Toast.makeText(context, "There was an error ", Toast.LENGTH_SHORT)
                .show();
        e.printStackTrace();
    }
}

但我不知道怎么样片段

but I don't know how about fragment

推荐答案

您必须 luanch 的意图和 putextera sendactivity 。 然后,你可以从活动启动片段。

You must luanch intent and putextera and sendactivity. Then you can launch fragment from activity.

这篇关于我怎样才能启动片段广播接收器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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