在当前短信内容的activity中写  

         Bundle bun = new Bundle();


        bun.putString("message", "短信内容");


        Intent in = new Intent(第二个Activity.this, 第一个Activity.class);


        in.putExtras(bun);

在要传内容的activity中写:


           Bundle bu = this.getIntent().getExtras();

String message = bu.getString("message");//获取短信内容

public class SMSReceiver extends BroadcastReceiver
{
    /*当收到短信时,就会触发此方法*/
    public void onReceive(Context context, Intent intent)
    {
        Bundle bundle = intent.getExtras();
        Object messages[] = (Object[]) bundle.get("pdus");
        SmsMessage smsMessage[] = new SmsMessage[messages.length];
        for (int n = 0; n < messages.length; n++)
        {
            smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
        }
        //调用显示短信内容的Activity
        Intent intent = new Intent();
        intent.setClass(this, MyView.class);
        intent.putExtra("sms_body", smsMessage[0].getMessageBody());
        startActivity(intent);
    }
}

回复三楼,按您所说的改了,
//调用显示短信内容的Activity
Intent intent2 = new Intent();
intent2.setClass(this, Activity01.class);
                   //setClass出错:The method setClass(Context, Class<?>) in the type Intent is not applicable for the arguments (SMSReceiver, Class<Activity01>)

intent2.putExtra("sms_body", smsMessage[0].getMessageBody());
startActivity(intent2);
                //startActivity出错:The method startActivity(Intent) is undefined for the type SMSReceiver

回复二楼: 二楼思路明确;
回复楼主: 有没有注意到二楼跟三楼的代码区别——intent.setClass(第二个Activity.this, 第一个Activity.class)和intent.setClass(this, 第一个Activity.class),当在方法中调用setClass()这个方法的时候,是可以用this的。挡在内部类中(比如事件监听类OnClickListener)调用这个方法的时候要变为Activity.class。希望能够帮助楼主。

The method setClass(Context, Class<?>) in the type Intent is not applicable for the arguments (GameV的更多相关文章

  1. 错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, MyFragment)

    Fragment newfragment =new MyFragment();fragmentTransaction.replace(R.layout.activity_main,newfragmen ...

  2. The method load(Class, Serializable) in the type HibernateTemplate is not applicable for the arguments (Class, int)

    引入别人的项目发现利用HibernateTemplate的load的方法报错了.错误提示为: The method load(Class, Serializable) in the type Hibe ...

  3. The method format(String, Object[]) in the type String is not applicable for the arguments

    今天,我弟遇到一个有意思的错误~ 程序: package com.mq.ceshi1; public class StringFormat { public static void main(Stri ...

  4. The method setOnClickListener(View.OnClickListener) in the type View is not applicable

    开始学习 android 了,学习的是高明鑫老师的android视频教程(android视频教学). 学到第八讲时, 在写动态设置时报错: The method setOnClickListener( ...

  5. The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (new View.OnClickListener(){}, String, int)

    package comxunfang.button; import android.support.v7.app.ActionBarActivity; import android.os.Bundle ...

  6. The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the arguments (int, SettingFragment, String)

    The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the ...

  7. The method setItems(String) in the type ForTokensTag is not applicable for the arguments (Object)

    1. 问题 看到这个错误以为是貌似jsp页面有误,c:forTokens标签用错了?? An error occurred at line: in the jsp file: /WEB-INF/pag ...

  8. [log4j]Error:The method getLogger(String) in the type Logger is not applicable for the arguments

    原因:本该导入import org.apache.log4j.Logger; 结果成了import java.util.logging.Logger; 如果硬把private static Logge ...

  9. .replace(R.id.container, new User()).commit();/The method replace(int, Fragment) in the type FragmentTransaction is not app

    提示错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arg ...

随机推荐

  1. java你应该学会什么

    给初学者之一:浅谈java及应用学java 先说什么是Javajava是一种面向对象语言,真正的面向对象,任何函数和变量都以类(class)封装起来至于什么是对象什么是类,我就不废话了关于这两个概念的 ...

  2. Linux中常用命令 <一>

    本笔记中记录的命令来源于 <Linux C 编程实战> ------------------------------------------------------------------ ...

  3. 看懂 MySQL 慢查询日志

    MySQL中的日志包括: 错误日志.二进制日志.通用查询日志.慢查询日志等等. 这里主要介绍下比较常用的两个功能:通用查询日志和慢查询日志. 1)通用查询日志:记录建立的客户端连接和执行的语句. 2) ...

  4. Codeforces 86D - Powerful array(莫队算法)

    题目链接:http://codeforces.com/problemset/problem/86/D 题目大意:给定一个数组,每次询问一个区间[l,r],设cnt[i]为数字i在该区间内的出现次数,求 ...

  5. BestCoder #88(1001 1002)

    Find Q Accepts: 392 Submissions: 780 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/131 ...

  6. 使用Python快速查询所有指定匹配KEY的办法

    import redis redis_ip = '10.10.14.224' redis_port = 18890 # 配置redis的连接办法 # http://blog.csdn.net/u010 ...

  7. es6js promise在ie中报错“未定义”

    解决办法,我使用https://cdn.bootcss.com/es6-promise/4.1.1/es6-promise.auto.min.js直接引入在html中,也可以安装相应的babel-po ...

  8. karma配置文件参数介绍

    目录结构 参数介绍 /*** * Created by laixiangran on 2015/12/22. * karma单元测试配置文件 */ module.exports = function( ...

  9. 转:[译]CSV 注入:被人低估的巨大风险

    转:https://yq.aliyun.com/articles/225847 原文地址:The Absurdly Underestimated Dangers of CSV Injection 原文 ...

  10. 转:gcc编译C++程序

    转:http://blog.csdn.net/liujiayu2/article/details/49864381 单个源文件生成可执行程序 下面是一个保存在文件 helloworld.cpp 中一个 ...