我想從一個活動發送值到另一個,但我得到空指針 異常請解決我的問題。第一個活動包含短信的詳細信息
短信發送到第二基於這些值的活動第二活動搜索聯繫人 否併發送回復短信。從一個活動傳遞值到另一個
public void onReceive(Context context, Intent intent)
{
// Get SMS map from Intent
Bundle bundle = null;
Bundle extras = intent.getExtras();
String messages = "";
String address = null,body=null;
if (extras != null)
{
// Get received SMS array
Object[] smsExtra = (Object[]) extras.get("pdus");
// Get ContentResolver object for pushing encrypted SMS to incoming folder
//ContentResolver contentResolver = context.getContentResolver();
for (int i = 0; i < smsExtra.length; ++i)
{
SmsMessage sms = SmsMessage.createFromPdu((byte[])smsExtra[i]);
body = sms.getMessageBody().toString();
address = sms.getOriginatingAddress();
messages += "SMS from " + address + " :\n";
messages += body + "\n";
// Here you can add any your code to work with incoming SMS
// I added encrypting of all received SMS
}
// Display SMS message
Toast.makeText(context, messages, Toast.LENGTH_SHORT).show();
Intent i=new Intent(context,AlertActivity.class);
bundle.putString("from",address);
bundle.putString("msg",body);
i.putExtras(bundle);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
活性2:
Intent i=getIntent();
Bundle bundle=i.getExtras();
String fromAdd=bundle.getString("from");
String msgBody=bundle.getString("body");
[**請參見本博客。這可以幫助你**](http://startandroiddevelopment.blogspot.in/2013/11/how-to-pass-boolean-int-string-integer.html) – 2013-11-04 04:51:17