rosjava / android_core

Android libraries for rosjava
145 stars 166 forks source link

MasterChooser onBackPressed can Causes MainActivity NodeMains to Crash #266

Closed stratomda closed 7 years ago

stratomda commented 7 years ago

If the user navigates back from the MasterChooser activity before a successful Master connection, a class that implements NodeMain and performs a publish (without null checking) can crash. For example, if back is pressed on the android_tutorial_teleop application and the user moves the VirtualJoystickView, the application crashes.

One solution could be to prevent the user from navigating back from the MasterChooser activity before a connection has been made. Thoughts on adding the following to MasterChooser?

  @Override
  public void onBackPressed() {
    //Prevent user from going back to Launcher Activity since no Master is connected.
    toast("Please connect to a Master!");
  }
jubeira commented 7 years ago

Oh yes, that is true indeed. I think you suggestion is OK. Another option would be to pause the application and leave it running in the background like when you press "home" (I think that's the default behavior for an Android app, am I right?)