Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

android - How can I launch fragment in broadcast receiver

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...