如何在BroadcastReceiver上使用PendingIntent

时间:2012-09-11 09:10:50

标签: android-intent ubuntu-11.04 ubuntu-10.10

我正在尝试设置一个消息应用程序:

  1. 首先我们在PreferenceConnector上设置一条消息,然后我们收到了 消息然后
  2. BroadcastReceiver检查消息内容是否等于
  3. 我想要一个PendingIntent。
  4. try {
            if (PreferenceConnector.readString(context,"MSG","tempmsg2").equals(messages[0].getMessageBody())) {
                Intent i=new Intent(context, SecureMobiActivity.class);                 
                PendingIntent pi=PendingIntent.getBroadcast(context, 0, i, 0);
            } else {
                Toast.makeText(Remotelock.this, "message are not equal!", Toast.LENGTH_LONG).show();
            }
            catch (Exception e) {
            // TODO: handle exception
                e.printStackTrace();
            }
    

1 个答案:

答案 0 :(得分:0)

答案很简单

try {
    if (PreferenceConnector.readString(context,"MSG","tempmsg2").equals(messages[0].getMessageBody())) {
        Intent i = new Intent(mContext,SecureMobiActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(i);
    } else {
        Toast.makeText(Remotelock.this, "message are not equal!", Toast.LENGTH_LONG).show();
    }
    catch (Exception e) {
    // TODO: handle exception
        e.printStackTrace();
    }