mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-21 11:54:15 +01:00
AndroidGCS: Unregister the activity broadcast receiver onStop(). Create it
onStart() instead.
This commit is contained in:
parent
57b91b7763
commit
37c4880fba
@ -81,36 +81,6 @@ public abstract class ObjectManagerActivity extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(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
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.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(),
|
Intent intent = new Intent(getApplicationContext(),
|
||||||
org.openpilot.androidgcs.telemetry.OPTelemetryService.class);
|
org.openpilot.androidgcs.telemetry.OPTelemetryService.class);
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
Log.d(TAG, "Attempting to bind: " + intent);
|
Log.d(TAG, "Attempting to bind: " + intent);
|
||||||
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -284,8 +290,10 @@ public abstract class ObjectManagerActivity extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
|
if (DEBUG) Log.d(TAG, "onStop()");
|
||||||
unbindService(mConnection);
|
unbindService(mConnection);
|
||||||
//unregisterReceiver(connectedReceiver);
|
unregisterReceiver(connectedReceiver);
|
||||||
|
connectedReceiver = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBind() {
|
public void onBind() {
|
||||||
|
@ -73,6 +73,7 @@ public class UAVLocation extends MapActivity
|
|||||||
UAVObjectManager objMngr;
|
UAVObjectManager objMngr;
|
||||||
boolean mBound = false;
|
boolean mBound = false;
|
||||||
boolean mConnected = false;
|
boolean mConnected = false;
|
||||||
|
BroadcastReceiver connectedReceiver;
|
||||||
org.openpilot.androidgcs.telemetry.OPTelemetryService.LocalBinder binder;
|
org.openpilot.androidgcs.telemetry.OPTelemetryService.LocalBinder binder;
|
||||||
|
|
||||||
GeoPoint homeLocation;
|
GeoPoint homeLocation;
|
||||||
@ -103,36 +104,6 @@ public class UAVLocation extends MapActivity
|
|||||||
|
|
||||||
mapView.postInvalidate();
|
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
|
//@Override
|
||||||
@ -291,10 +262,53 @@ public class UAVLocation extends MapActivity
|
|||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.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);
|
Intent intent = new Intent(this, OPTelemetryService.class);
|
||||||
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
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() {
|
public void onBind() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user