简体   繁体   English

Android-在活动上调用finish()不会阻止其运行

[英]Android - calling finish() on activity does not stop it from running

So I've looked up similar problems to this, and have followed the advice in those threads, but it seems to give me no change in behavior. 因此,我查找了与此类似的问题,并按照这些线程中的建议进行了操作,但这似乎并没有改变我的行为。

So I'm writing an app that essentially notifies the user when they're going too fast or too slow based on GPS onLocationChanged() calls. 因此,我正在编写一个应用程序,该应用程序实际上会根据GPS onLocationChanged()调用通知用户运行得太快或太慢。 I overrided the onBackPressed() method to finish() and return but the activity continues to run in the background when I go back to the main activity. 我将onBackPressed()方法重写为finish()并返回,但是当我返回主活动时,该活动继续在后台运行。

To be clear, I DO want the activity to run when the app is minimized or screen is off. 明确地说,我确实希望活动在应用程序最小化或屏幕关闭时运行。 I only want it to stop when the user goes back to the menu (IE, hits the back button) 我只希望它在用户返回菜单时停止(即,单击后退按钮)

Here's the link to the class on pastebin: http://pastebin.com/V7z5c3HH 这是pastebin上的类的链接: http : //pastebin.com/V7z5c3HH

Thanks for your help! 谢谢你的帮助! =D = D

Unsubscribe your location listener in the onDestroy method. 使用onDestroy方法取消订阅位置侦听器。 However, what you need for your GPS processing is probably a Service, not an Activity. 但是,GPS处理所需的可能是服务,而不是活动。

You need to remove the updates for that listener. 您需要删除该侦听器的更新。

@Override
protected void onDestroy() {
    locationManager.removeUpdates(locationListener);
    super.onDestroy();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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