3

I've developed one location based app which uses Google Maps API and GPS. In my app I've used finish() and finishAffinity()in certain methods to close the app.

It is working fine with all the mobiles except the HTC One M8 (Marshmallow). In that mobile, the app is not closing at any instant and I used a separate thread for the closing activity to be done. I don't know what the problem is.. It is happening only on Marshmallow devices.

My code (after onCreate()):

public void onGpsClick(View v) {
    Button stop = (Button) findViewById(R.id.button3);

    Log.v(TAG, "onClick");


    locationListener = new MyLocationListener();

    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

        return;
    }
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 10, locationListener);

    stop.setOnClickListener(new View.OnClickListener() {
        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override
        public void onClick(View v) {
            pb.setVisibility(View.INVISIBLE);

            Toast.makeText(getApplicationContext(), "GPS Error: Try after some time ", Toast.LENGTH_LONG).show();
            notification.setAutoCancel(true);


            finishAffinity();
        }
    });
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        public void run() {
            if (Glast == 11) {
                Toast.makeText(getApplicationContext(), "Your are near by..", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getApplicationContext(), "GPS Timeout.", Toast.LENGTH_LONG).show();
                finish();
            }
        }
    }, 15000);

}
Surya
  • 47
  • 8

1 Answers1

0

I used in my apps like this ;

getMyActivity().finish();
System.exit(0);