我创建了两个活动页面. MainActivity和进行的活动.我正在MainActivity页面中从用户那里获取数据,并且通过意图我正在发送以继续进行活动.
在我输入电话号码的页面上,然后单击发送按钮.它成功发送了消息,但此后我创建了开始活动以移至mainactivity页面.它正在移至主要活动,但几秒钟后会自动开始进行活动.
1.在mainActivity中我正在发送列表
public void Proceed(View view){
if(planetsList.size()==0){
Toast.makeText(MainActivity.this, "Please Add Product", Toast.LENGTH_SHORT).show();
return;
}
Intent intent = new Intent(MainActivity.this, Proceed.class);
intent.putExtra("list_product", planetsList);
Log.e("gjdgfl",Integer.toString(planetsList.size()));
startActivity(intent);
}
2.在继续页面中,编码是
send.setonClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String no = mnumber.getText().toString();
Float netTotal = 0.1f;
ArrayList<Planet> myList = getIntent().getParcelableArrayListExtra("list_product");
Log.e("hai1",Integer.toString(myList.size()));
StringBuilder sb = new StringBuilder();
for (Planet temp : myList) {
sb.append(temp.getName()).append(" ").append(temp.getPerkg()).append("*").append(temp.getTotkg()).append("=").append(temp.getTotamt()).append("\n");
netTotal += temp.getTotamt();
}
sb.append("Total Amount is -"+netTotal);
System.out.println(sb.toString());
System.out.println(no);
String msg = sb.toString();
Intent intent=new Intent(getApplicationContext(),Proceed.class);
PendingIntent pi=PendingIntent.getActivity(getApplicationContext(), 0, intent,0);
SmsManager sms=SmsManager.getDefault();
sms.sendTextMessage(no, null, msg, pi,null);
Toast.makeText(getApplicationContext(), "Message Sent successfully!", Toast.LENGTH_LONG).show();
AlertDialog.Builder builder = new AlertDialog.Builder(Proceed.this);
builder.setTitle("Confirmation");
builder.setMessage("Message Sent Successfully")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent1 = new Intent(Proceed.this,MainActivity.class);
intent1.putExtra("exit_on_sent", true);
startActivity(intent1);
}
});
AlertDialog alert = builder.create();
alert.show();
}
解决方法:
将PendingIntent类更改为MainActivity,在发送短信后它将重定向到MainActivity.
Intent intent=new Intent(getApplicationContext(),MainActivity.class);
PendingIntent pi=PendingIntent.getActivity(getApplicationContext(), 0, intent,0);
SmsManager sms=SmsManager.getDefault();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。