Android应用不支持版本19

时间:2014-04-11 11:59:36

标签: java android android-emulator

在我的Android应用程序中,存在验证过程,其中用户的移动号码通过发送随机码来验证。用户必须输入它作为验证..我在版本17的模拟器中检查了我的应用程序它工作正常。但是在logcat中会出现一些错误消息。当我检查版本19的emulaturs应用程序崩溃..如果有人可以帮助请帮助..我给下面的代码和logcat也

SignUpActivity

public class SignUpActivity extends Activity
{
    EditText editTextUserName,editTextPassword,editTextConfirmPassword, editMobileNumber;
    Button btnCreateAccount;
    final Context context = this;


    // Progress Dialog
        private ProgressDialog pDialog;
        JSONParser jsonParser = new JSONParser();
        LoginDataBaseAdapter loginDataBaseAdapter;

private static String url_create_data = "http://iascpl.com/app/create_data1.php";

    // JSON Node names
    private static final String TAG_SUCCESS = "success";    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.signup_xm); 

        // get Instance  of Database Adapter
                loginDataBaseAdapter=new LoginDataBaseAdapter(this);
                loginDataBaseAdapter=loginDataBaseAdapter.open();

                // Get References of Views              
                editTextUserName=(EditText)findViewById(R.id.editTextUserName);
                editTextPassword=(EditText)findViewById(R.id.editTextPassword);
                editTextConfirmPassword=(EditText)findViewById(R.id.editTextConfirmPassword);
                editMobileNumber = (EditText)findViewById(R.id.mobileNumber);

                btnCreateAccount=(Button)findViewById(R.id.buttonCreateAccount);

                btnCreateAccount.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub

                        if (isNetworkAvailable(getBaseContext()))
                        {

                        String name=editTextUserName.getText().toString();
                        String password=editTextPassword.getText().toString();
                        String confirmPassword=editTextConfirmPassword.getText().toString();

                        String phoneNo = editMobileNumber.getText().toString();
                        //String sms = Integer.toString(number);


                        //Intent intent = new Intent(SignUpActivity.this, RegisterActivity.class);

                        //intent.putExtra("number", sms + "");
                        //startActivity(intent);            

                        //new CreateNewProduct().execute();                         

                        // check if any of the fields are vacant
                        if(name.equals("")||password.equals("")||confirmPassword.equals("") || phoneNo.equals(""))
                        {
                                Toast.makeText(getApplicationContext(), "Field Vaccant", Toast.LENGTH_LONG).show();
                                return;
                        }
                        // check if both password matches
                        if(!password.equals(confirmPassword))
                        {
                            Toast.makeText(getApplicationContext(), "Password does not match", Toast.LENGTH_LONG).show();
                            return;
                        }
                        else
                        {
                            new CreateNewProduct().execute();


                         }

                           // Intent intent = new Intent(SignUpActivity.this, RegisterActivity.class);

                          //  intent.putExtra("number", sms + "");
                           // startActivity(intent);
                        }
                        else
                        {
                            Toast.makeText(SignUpActivity.this, "No Internet Connection..!!!.. Please activate the WiFi or mobile data to complete the signup process.", Toast.LENGTH_LONG).show(); 
                        }

                        }


                    });
                }




    protected boolean isNetworkAvailable(Context context) {
        // TODO Auto-generated method stub
        return ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo() != null;

    }




    private void sendSMS(String phoneNumber, String message)
    {
        String SENT = "SMS_SENT";
        String DELIVERED = "SMS_DELIVERED";

        PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
            new Intent(SENT), 0);

        PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
            new Intent(DELIVERED), 0);

      //---when the SMS has been sent---
        registerReceiver(new BroadcastReceiver(){
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode())
                {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "SMS sent", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                        Toast.makeText(getBaseContext(), "Generic failure", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_NO_SERVICE:
                        Toast.makeText(getBaseContext(), "No service", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_NULL_PDU:
                        Toast.makeText(getBaseContext(), "Null PDU", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_RADIO_OFF:
                        Toast.makeText(getBaseContext(), "Radio off", 
                                Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        },new IntentFilter(SENT));

        //---when the SMS has been delivered---
        registerReceiver(new BroadcastReceiver(){
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode())
                {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "SMS delivered", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case Activity.RESULT_CANCELED:
                        Toast.makeText(getBaseContext(), "SMS not delivered", 
                                Toast.LENGTH_SHORT).show();
                        break;                        
                }
            }
        }, new IntentFilter(DELIVERED));        

        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);       


    }



    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub

        super.onDestroy();

        loginDataBaseAdapter.close();
    }



    /**
     * Background Async Task to Create new product
     * */
    class CreateNewProduct extends AsyncTask<String, String, String> {

        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(SignUpActivity.this);
            pDialog.setMessage("Creating a new account..");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }

        /**
         * Creating product
         * */
        protected String doInBackground(String... args) {

            String name = editTextUserName.getText().toString();
            String password = editTextPassword.getText().toString();
            String mobile = editMobileNumber.getText().toString();      

            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("name", name));
            params.add(new BasicNameValuePair("password", password));
            params.add(new BasicNameValuePair("mobile", mobile));

            // getting JSON Object
            // Note that create product url accepts POST method
            JSONObject json = jsonParser.makeHttpRequest(url_create_data,
                    "POST", params);

            // check log cat fro response
            Log.d("Create Response", json.toString());

            // check for success tag
            try {
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    // successfully created product 
                     // Save the Data in Database
                    Random r = new Random();
                    int number =r.nextInt(9999 - 1000) + 1000;

                    String phoneNo = editMobileNumber.getText().toString();
                    StringTokenizer st=new StringTokenizer(phoneNo,",");
                    String sms = Integer.toString(number);
                    //String tempMobileNumber = (String)st.nextElement();
                    //StringTokenizer st=new StringTokenizer(phoneNo,",");
                    while (st.hasMoreElements())

                    {

                        String tempMobileNumber = (String)st.nextElement();
                        if(tempMobileNumber.length()>0 && sms.trim().length()>0) 
                        {
                            sendSMS(tempMobileNumber, sms);

                        }
                        else                        
                        {                
                            Toast.makeText(getBaseContext(), 
                                    "Please enter both phone number and message.", 
                                    Toast.LENGTH_SHORT).show();
                        }               

                    }

                    loginDataBaseAdapter.insertEntry(name, password);


                    Intent i = new Intent(SignUpActivity.this, RegisterActivity.class);             
                    i.putExtra("number", sms + "");
                    startActivity(i);                   
                    //closing this screen
                    finish();
                } else {
                    // failed to create product
                    return "false";
                }       

            } catch (JSONException e) {
                e.printStackTrace();
            }
            return null;
        }
        /**
         * After completing background task Dismiss the progress dialog
         * **/

        protected void onPostExecute(String result)

        {           // TODO Auto-generated method stub
            super.onPostExecute(result);
                        if (result == "false"){

                            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                                    context);

                                // set title
                                alertDialogBuilder.setTitle("Username already Exists...!");

                                // set dialog message
                                alertDialogBuilder
                                    .setMessage("Select another Username. Click 'Ok' to continue.")
                                    .setCancelable(false)

                                    .setNegativeButton("OK",new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog,int id) {
                                            // if this button is clicked, just close
                                            // the dialog box and do nothing
                                            dialog.cancel();
                                        }
                                    });

                                    // create alert dialog
                                    AlertDialog alertDialog = alertDialogBuilder.create();

                                    // show it
                                    alertDialog.show(); } 



           // Toast.makeText(SignUpActivity.this, "User Name already exists. Please choose another user name ", Toast.LENGTH_LONG).show();
                        pDialog.dismiss();
        }
    }
     @Override
    public void onBackPressed() {
        // TODO Auto-generated method stub
        super.onBackPressed();
        Intent intent = new Intent(SignUpActivity.this, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);//intent for StartPage
        finish();
    }




}

logcat的

04-11 11:50:34.859: E/ActivityThread(846): Activity com.example.numerologyprediction.SignUpActivity has leaked IntentReceiver com.example.numerologyprediction.SignUpActivity$3@412aa300 that was originally registered here. Are you missing a call to unregisterReceiver()?
04-11 11:50:34.859: E/ActivityThread(846): android.app.IntentReceiverLeaked: Activity com.example.numerologyprediction.SignUpActivity has leaked IntentReceiver com.example.numerologyprediction.SignUpActivity$3@412aa300 that was originally registered here. Are you missing a call to unregisterReceiver()?
04-11 11:50:34.859: E/ActivityThread(846):  at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:795)
04-11 11:50:34.859: E/ActivityThread(846):  at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:596)
04-11 11:50:34.859: E/ActivityThread(846):  at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1316)
04-11 11:50:34.859: E/ActivityThread(846):  at android.app.ContextImpl.registerReceiver(ContextImpl.java:1296)
04-11 11:50:34.859: E/ActivityThread(846):  at android.app.ContextImpl.registerReceiver(ContextImpl.java:1290)
04-11 11:50:34.859: E/ActivityThread(846):  at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:423)
04-11 11:50:34.859: E/ActivityThread(846):  at com.example.numerologyprediction.SignUpActivity.sendSMS(SignUpActivity.java:180)
04-11 11:50:34.859: E/ActivityThread(846):  at com.example.numerologyprediction.SignUpActivity.access$3(SignUpActivity.java:138)
04-11 11:50:34.859: E/ActivityThread(846):  at com.example.numerologyprediction.SignUpActivity$CreateNewProduct.doInBackground(SignUpActivity.java:279)
04-11 11:50:34.859: E/ActivityThread(846):  at com.example.numerologyprediction.SignUpActivity$CreateNewProduct.doInBackground(SignUpActivity.java:1)
04-11 11:50:34.859: E/ActivityThread(846):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-11 11:50:34.859: E/ActivityThread(846):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-11 11:50:34.859: E/ActivityThread(846):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
04-11 11:50:34.859: E/ActivityThread(846):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-11 11:50:34.859: E/ActivityThread(846):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-11 11:50:34.859: E/ActivityThread(846):  at java.lang.Thread.run(Thread.java:856)
04-11 11:50:35.000: E/ActivityThread(846): Activity com.example.numerologyprediction.SignUpActivity has leaked IntentReceiver com.example.numerologyprediction.SignUpActivity$2@412a9ca8 that was originally registered here. Are you missing a call to unregisterReceiver()?
04-11 11:50:35.000: E/ActivityThread(846): android.app.IntentReceiverLeaked: Activity com.example.numerologyprediction.SignUpActivity has leaked IntentReceiver com.example.numerologyprediction.SignUpActivity$2@412a9ca8 that was originally registered here. Are you missing a call to unregisterReceiver()?
04-11 11:50:35.000: E/ActivityThread(846):  at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:795)
04-11 11:50:35.000: E/ActivityThread(846):  at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:596)
04-11 11:50:35.000: E/ActivityThread(846):  at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1316)
04-11 11:50:35.000: E/ActivityThread(846):  at android.app.ContextImpl.registerReceiver(ContextImpl.java:1296)
04-11 11:50:35.000: E/ActivityThread(846):  at android.app.ContextImpl.registerReceiver(ContextImpl.java:1290)
04-11 11:50:35.000: E/ActivityThread(846):  at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:423)
04-11 11:50:35.000: E/ActivityThread(846):  at com.example.numerologyprediction.SignUpActivity.sendSMS(SignUpActivity.java:150)
04-11 11:50:35.000: E/ActivityThread(846):  at com.example.numerologyprediction.SignUpActivity.access$3(SignUpActivity.java:138)
04-11 11:50:35.000: E/ActivityThread(846):  at com.example.numerologyprediction.SignUpActivity$CreateNewProduct.doInBackground(SignUpActivity.java:279)
04-11 11:50:35.000: E/ActivityThread(846):  at com.example.numerologyprediction.SignUpActivity$CreateNewProduct.doInBackground(SignUpActivity.java:1)
04-11 11:50:35.000: E/ActivityThread(846):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-11 11:50:35.000: E/ActivityThread(846):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-11 11:50:35.000: E/ActivityThread(846):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
04-11 11:50:35.000: E/ActivityThread(846):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-11 11:50:35.000: E/ActivityThread(846):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-11 11:50:35.000: E/ActivityThread(846):  at java.lang.Thread.run(Thread.java:856)

2 个答案:

答案 0 :(得分:1)

如果应用程序在版本17的模拟器中正常工作,您可以检查版本19,如果应用程序在17中工作而不在19中工作意味着..您可以检查内存空间是否足够。如果你做了很多计算,比如像json这样的后台进程,并且所有有错误的机会,那么应用程序可以停止之前的活动。因此,请检查应用程序是否因内存问题而无法正常工作。

否则,您可以查看使用最新KitKat版本而不是仿真器的手机..还需要检查是否有足够的内存空间才能正常使用该应用程序。

答案 1 :(得分:0)

onPause()方法中,取消注册广播接收器:

unregisterReceiver(broadcastReceiverInstance);

Alos查看此链接herehere

希望这有帮助。