3

我开发了一个基于位置的应用程序,它使用Google Maps API和GPS。在我的应用程序中,我在某些方法中使用了finish()finishAffinity()来关闭应用程序。线程未运行在棉花糖设备

它工作正常,除了HTC One M8(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); 

} 
+0

发布您的代码太 –

+0

我张贴@vivek – Surya

回答

0

我在我的应用程序是这样使用;

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

感谢Fuat.Let我也试试这个。 – Surya