How to load activity from BroadcastReceiver onReceive

故事扮演 提交于 2019-12-24 11:41:53

问题


I want to load an activity from the BroadcastReceiver onReceive method. I have 2 activities, one is the main and the second I created. I want to load the second activity from onReceive but it's loading the main activity and I don't know why..

This is the intent on onReceive():

Intent i = new Intent(context, BTNotifierWarning.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);   

this is the BTNotifierWarning class:

package com.btnotifier;

import android.app.Activity;
import android.os.Bundle;

public class BTNotifierWarning extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.warning);

        // TODO Auto-generated method stub
    }
}

and this is the warning xml layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".BTNotifierWarning" >

why it's happening?

Thanks!

来源:https://stackoverflow.com/questions/17906466/how-to-load-activity-from-broadcastreceiver-onreceive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!