简体   繁体   English

GPS位置更改时如何将Android应用程序带回前台

[英]How to bring back an Android application to foreground when GPS location is changed

I am building a Android application which gives Travel Maps.User can navigate away from my application. 我正在构建一个提供Travel Maps的Android应用程序。用户可以离开我的应用程序。 Ex - Pressing Home button. 例如-按“主页”按钮。 I want do is, bring back the application on location change.I want to show some notifications on special GPS coordinates. 我想要做的是,使应用程序重新定位。我想在特殊的GPS坐标上显示一些通知。 I am using onLocationChanged() method to do my tasks. 我正在使用onLocationChanged()方法执行任务。 But I cant find out a way to bring the app to foreground. 但是我找不到一种将应用程序置于前台的方法。 Can you please help me? 你能帮我么?

I don't think you can have your application come to the foreground like that but you can probably show a notification in the notification bar instead. 我认为您不能像这样使您的应用程序出现在前台,但是您可能可以在通知栏中显示通知。 When the user selects that notification you can show your application again. 当用户选择该通知时,您可以再次显示您的应用程序。

First I have not done this. 首先,我没有这样做。 But at least you can try. 但是至少您可以尝试。 Inside onLocationChanged() callback put 在onLocationChanged()回调内部

Intent startActivity = new Intent(this,your_class.class ); 
startActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
PendingIntent i = PendingIntent.getActivity(this, 0, startActivity, 0);

Then start that Intent. 然后启动该意图。

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

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