当进入/退出地理围栏区域时,我希望将活动直接带到前台。
我有5个地理围栏区域,并希望当我进入地理围栏区域A(在经纬度中指定)时将ActivityA带到前台,当我在地理围栏时活动B是B,以此类推。(这是一个非消费者应用程序,所以我不介意直接从服务调用活动到前台。)
我在Android的地理围栏上读过this documentation。当不同的活动接收到不同地理围栏区域的ID时,我该如何调用它们?
待定意图:
public class MainActivity extends FragmentActivity {
...
private PendingIntent getTransitionPendingIntent() {
Intent intent = new Intent(this,
ReceiveTransitionsIntentService.class);
return PendingIntent.getService(
this,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
...
}和处理程序的意图:
protected void onHandleIntent(Intent intent) {
if (LocationClient.hasError(intent)) {
int errorCode = LocationClient.getErrorCode(intent);
Log.e("ReceiveTransitionsIntentService",
"Location Services error: " +
Integer.toString(errorCode));
} else {
// Get the type of transition (entry or exit)
int transitionType =
LocationClient.getGeofenceTransition(intent);
// Test that a valid transition was reported
if (
(transitionType == Geofence.GEOFENCE_TRANSITION_ENTER)
||
(transitionType == Geofence.GEOFENCE_TRANSITION_EXIT)
) {
List <Geofence> triggerList =
getTriggeringGeofences(intent);
String[] triggerIds = new String[geofenceList.size()];
for (int i = 0; i < triggerIds.length; i++) {
// Store the Id of each geofence
triggerIds[i] = triggerList.get(i).getRequestId();
}
}
} else {
Log.e("ReceiveTransitionsIntentService",
"Geofence transition error: " +
Integer.toString()transitionType));
}
}发布于 2014-02-28 23:28:30
documentation声明你不应该这样做:
从位置服务发送的意图可以触发应用程序中的各种操作,但您不应该让它启动活动或片段,因为组件应该仅在响应用户操作时才可见。在许多情况下,IntentService是处理意图的好方法。
https://stackoverflow.com/questions/18191786
复制相似问题