I am using Gimbal SDK for geofence functionality in my android application. The sample code provided by them make me surprise. The sample code is as below package com.gimbal.hello_gimbal_android;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.gimbal.android.CommunicationManager;
import com.gimbal.android.Gimbal;
import com.gimbal.android.PlaceEventListener;
import com.gimbal.android.PlaceManager;
import com.gimbal.android.Visit;
public class MainActivity extends ActionBarActivity {
private PlaceManager placeManager;
private PlaceEventListener placeEventListener;
private ArrayAdapter<String> listAdapter;
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1);
listView = (ListView) findViewById(R.id.list);
listView.setAdapter(listAdapter);
listAdapter.add("Setting Gimbal API Key");
listAdapter.notifyDataSetChanged();
Gimbal.setApiKey(this.getApplication(), "YOUR_API_KEY_HERE");
placeEventListener = new PlaceEventListener() {
@Override
public void onVisitStart(Visit visit) {
listAdapter.add(String.format("Start Visit for %s", visit.getPlace().getName()));
listAdapter.notifyDataSetChanged();
}
@Override
public void onVisitEnd(Visit visit) {
listAdapter.add(String.format("End Visit for %s", visit.getPlace().getName()));
listAdapter.notifyDataSetChanged();
}
};
placeManager = PlaceManager.getInstance();
placeManager.addListener(placeEventListener);
placeManager.startMonitoring();
CommunicationManager.getInstance().startReceivingCommunications();
}
}
Their sample App github link.
Now their place events listener implementation make me surprise. I am expecting a pending intent for service or some kind of broadcasting of intent for listening these place events, as most of such libraries used to notify application. Which is fine for obvious. Because such events should be triggered even if app is in killed state. But here PlaceEventListener is a just an abstract class and we are making an instance of it using new Operator and providing the incomplete functionality of abstract methods.
So, when my activity will destroy, their SDK does not suppose to able give callback in onVisitStart() and PlaceEventListener () method, as placeEventListener instance should be destroyed or null.
My concern is
- Gimabl SDK prevent destroying the main activity class instance from
Garbage collector just for keeping the placeEventListner
instance reference? If so, I think this is a bad design as If we can use new placeEventListner from so many activities and all of these will prevent GC. - Also Running a background service just to listen to these event does not seems fine to me. Their SDK should make some component of my android application take birth (example like firing some service or invoking a broadcast receiver by broadcasting a place event).
*Edit: One possible way is implementing the listener interface in Application class of Android application, but I am trying to avoid it due to some other reasons. So, where I suppose to implement it?