【发布时间】:2016-02-29 13:26:29
【问题描述】:
我开发了一款使用 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);
}
【问题讨论】:
标签: android android-6.0-marshmallow activity-finish htc-android