Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在创建一个使用 GPS 的 Android 应用程序。我想提示用户打开位置服务并阻止程序进行,除非它们被打开。我尝试使用 while 循环,但由于某种原因它不起作用,并且出现内存不足错误。关于如何实现这样的事情的任何想法?
你不能长时间阻塞 UI 线程,否则你会得到可怕的 ANR(应用程序无响应)对话框。像 Android 这样的 GUI 框架是基于事件的。finish()因此,在单击对话框的“确定”按钮时,使用对话框通知用户先决条件和您的活动。
finish()