为什么活动在模拟器上工作正常但在设备上关闭?

时间:2011-11-03 10:21:00

标签: android-emulator android

我已经将此活动发送给用户。这在模拟器上工作正常但在设备上强行关闭..当我提供按钮(发送/取消)的监听器而不覆盖on Click方法时它也会得到强行关闭。

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class SendInvitationActivity extends Activity implements View.OnClickListener {

    Button btncancel, btnsend;
    EditText et_name, et_phone;

    @Override 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.invite);

        //et_name=new EditText(getApplicationContext());
        et_name = (EditText) findViewById(R.id.invite_name);
        //et_name.setText("");

        //et_phone=new EditText(getApplicationContext());
        et_phone = (EditText) findViewById(R.id.invite_phno);
        //et_phone.setText("");

        //btncancel=new Button(getApplicationContext());
        btncancel=(Button) findViewById(R.id.buttonNotWorking);

             **it is closing even on providing listener here... 

            btncancel.setOnClickListener(this);

        //btnsend=new Button(getApplicationContext());
        btnsend = (Button) findViewById(R.id.button1);

        btncancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent i = new Intent();
                i.setClassName("a.b.c","a.b.c.firstactivity");
                startActivity(i);
                finish();

            }
        });



        btnsend.setOnClickListener(this);

    }




    public void sendMessage(String pno){
        String message = "Hi, Please download and install Family Finder to connect with me";
        PendingIntent pi = PendingIntent.getActivity(this, 0,
                new Intent(this, SendInvitationActivity.class), 0);
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(pno, null, message, null, null);


     }

    @Override
    public void onClick(View v) {
        if (v == btnsend) {

            String phoneNo = et_phone.getText().toString();
            String name = et_name.getText().toString();
            String message = "Hi, Please download and install Family Finder to connect with me";
            if (phoneNo.length() > 0 && name.length() > 0) {
                PendingIntent pi = PendingIntent.getActivity(this, 0,
                        new Intent(this, SendInvitationActivity.class), 0);
                SmsManager sms = SmsManager.getDefault();
                sms.sendTextMessage(phoneNo, null, message, null, null);

                Intent it=new Intent();
                it.setClassName("com.a3.activity","com.a3.activity.FamilyFinderActivity");
                startActivity(it);
                finish();



            } else
                Toast.makeText(this,
                        "Please enter both Name and Phone number.",
                        Toast.LENGTH_SHORT).show();
        }
        /*if (v == btncancel) {
            Intent i = new Intent();
            i.setClassName("a.b.c",
                    "a.b.c.firstactivity");
            startActivity(i);
            finish();
        }*/

    }


}

1 个答案:

答案 0 :(得分:1)

如果通过设置断点并检查logcat来调试它,将会有所帮助。