线程未在Marshmallow设备中运行

时间:2016-02-29 13:26:30

标签: android android-6.0-marshmallow activity-finish htc-android

我开发了一款基于位置的应用,它使用Google Maps API和GPS。在我的应用中,我在某些方法中使用finish()finishAffinity()来关闭应用。

除了 HTC One M8 (Marshmallow)以外,所有手机都能正常使用。在该移动设备中,应用程序不会在任何时刻关闭,我使用单独的线程来完成关闭活动。我不知道问题是什么......它只发生在Marshmallow设备上。

我的代码(在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);

}

1 个答案:

答案 0 :(得分:0)

我在我这样的应用程序中使用过;

nvarchar(max)