1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

AndroidGCS: Unregister the activity broadcast receiver onStop(). Create it

onStart() instead.
This commit is contained in:
James Cotton 2012-08-10 00:19:52 -05:00
parent d46a865229
commit 54e239d6cb
2 changed files with 83 additions and 61 deletions

View File

@ -81,36 +81,6 @@ public abstract class ObjectManagerActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
connectedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (DEBUG)
Log.d(TAG, "Received intent");
TelemTask task;
if(intent.getAction().compareTo(OPTelemetryService.INTENT_ACTION_CONNECTED) == 0) {
if(binder == null)
return;
if((task = binder.getTelemTask(0)) == null)
return;
objMngr = task.getObjectManager();
mConnected = true;
onOPConnected();
Log.d(TAG, "Connected()");
} else if (intent.getAction().compareTo(OPTelemetryService.INTENT_ACTION_DISCONNECTED) == 0) {
objMngr = null;
mConnected = false;
onOPDisconnected();
Log.d(TAG, "Disonnected()");
}
}
};
IntentFilter filter = new IntentFilter();
filter.addCategory(OPTelemetryService.INTENT_CATEGORY_GCS);
filter.addAction(OPTelemetryService.INTENT_ACTION_CONNECTED);
filter.addAction(OPTelemetryService.INTENT_ACTION_DISCONNECTED);
registerReceiver(connectedReceiver, filter);
}
/**
@ -271,11 +241,47 @@ public abstract class ObjectManagerActivity extends Activity {
@Override
public void onStart() {
super.onStart();
if (DEBUG) Log.d(TAG, "onStart()");
// Register a receiver to get connected/disconnected signals from the telemetry
// service
connectedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (DEBUG)
Log.d(TAG, "Received intent");
TelemTask task;
if(intent.getAction().compareTo(OPTelemetryService.INTENT_ACTION_CONNECTED) == 0) {
if(binder == null)
return;
if((task = binder.getTelemTask(0)) == null)
return;
objMngr = task.getObjectManager();
mConnected = true;
onOPConnected();
Log.d(TAG, "Connected()");
} else if (intent.getAction().compareTo(OPTelemetryService.INTENT_ACTION_DISCONNECTED) == 0) {
objMngr = null;
mConnected = false;
onOPDisconnected();
Log.d(TAG, "Disonnected()");
}
}
};
// Set up the filters
IntentFilter filter = new IntentFilter();
filter.addCategory(OPTelemetryService.INTENT_CATEGORY_GCS);
filter.addAction(OPTelemetryService.INTENT_ACTION_CONNECTED);
filter.addAction(OPTelemetryService.INTENT_ACTION_DISCONNECTED);
registerReceiver(connectedReceiver, filter);
// Bind to the telemetry service (which will start it)
Intent intent = new Intent(getApplicationContext(),
org.openpilot.androidgcs.telemetry.OPTelemetryService.class);
if (DEBUG)
Log.d(TAG, "Attempting to bind: " + intent);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
/**
@ -284,8 +290,10 @@ public abstract class ObjectManagerActivity extends Activity {
@Override
public void onStop() {
super.onStop();
if (DEBUG) Log.d(TAG, "onStop()");
unbindService(mConnection);
//unregisterReceiver(connectedReceiver);
unregisterReceiver(connectedReceiver);
connectedReceiver = null;
}
public void onBind() {

View File

@ -73,6 +73,7 @@ public class UAVLocation extends MapActivity
UAVObjectManager objMngr;
boolean mBound = false;
boolean mConnected = false;
BroadcastReceiver connectedReceiver;
org.openpilot.androidgcs.telemetry.OPTelemetryService.LocalBinder binder;
GeoPoint homeLocation;
@ -103,36 +104,6 @@ public class UAVLocation extends MapActivity
mapView.postInvalidate();
// ObjectManager related stuff (can't inherit standard class)
BroadcastReceiver connectedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "Received intent");
TelemTask task;
if(intent.getAction().compareTo(OPTelemetryService.INTENT_ACTION_CONNECTED) == 0) {
if(binder == null)
return;
if((task = binder.getTelemTask(0)) == null)
return;
objMngr = task.getObjectManager();
mConnected = true;
onOPConnected();
Log.d(TAG, "Connected()");
} else if (intent.getAction().compareTo(OPTelemetryService.INTENT_ACTION_DISCONNECTED) == 0) {
objMngr = null;
mConnected = false;
onOPDisconnected();
Log.d(TAG, "Disonnected()");
}
}
};
IntentFilter filter = new IntentFilter();
filter.addCategory(OPTelemetryService.INTENT_CATEGORY_GCS);
filter.addAction(OPTelemetryService.INTENT_ACTION_CONNECTED);
filter.addAction(OPTelemetryService.INTENT_ACTION_DISCONNECTED);
registerReceiver(connectedReceiver, filter);
}
//@Override
@ -291,10 +262,53 @@ public class UAVLocation extends MapActivity
@Override
public void onStart() {
super.onStart();
// ObjectManager related stuff (can't inherit standard class)
connectedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "Received intent");
TelemTask task;
if(intent.getAction().compareTo(OPTelemetryService.INTENT_ACTION_CONNECTED) == 0) {
if(binder == null)
return;
if((task = binder.getTelemTask(0)) == null)
return;
objMngr = task.getObjectManager();
mConnected = true;
onOPConnected();
Log.d(TAG, "Connected()");
} else if (intent.getAction().compareTo(OPTelemetryService.INTENT_ACTION_DISCONNECTED) == 0) {
objMngr = null;
mConnected = false;
onOPDisconnected();
Log.d(TAG, "Disonnected()");
}
}
};
IntentFilter filter = new IntentFilter();
filter.addCategory(OPTelemetryService.INTENT_CATEGORY_GCS);
filter.addAction(OPTelemetryService.INTENT_ACTION_CONNECTED);
filter.addAction(OPTelemetryService.INTENT_ACTION_DISCONNECTED);
registerReceiver(connectedReceiver, filter);
Intent intent = new Intent(this, OPTelemetryService.class);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
/**
* When stopping disconnect form the service and the broadcast receiver
*/
@Override
public void onStop() {
super.onStop();
if (DEBUG) Log.d(TAG, "onStop()");
unbindService(mConnection);
unregisterReceiver(connectedReceiver);
connectedReceiver = null;
}
public void onBind() {
}