简体   繁体   中英

Android app not working on version 19

In my android application there is a process of verification is there where user's mobile number is verified by sending a random code. User has to enter it as a verification.. I checked my app in emulator of version 17 it is working fine . But in logcat there is some error messages are coming. When I checked in emulaturs of version 19 the app is crashing.. If anyone can help pls help.. I am giving the code below and the logcat also

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)

If the app is working fine in Emulator of version 17 you can check with version 19 if the app is working in 17 and not working in 19 means.. you can check whether the memory space is adequate. If your doing so many calculations like background processes like json and all there is a chance for error the application can stop the previous activity. So check whether the app is not working because of memory problems.

Otherwise you can check on mobile phones which working on the latest KitKat version instead of emulators.. there also u need to check whether adequate memory space is there for proper working of the app.

In onPause() method, unregister your broadcast receiver :

unregisterReceiver(broadcastReceiverInstance);

Alos check this links here and here

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM