-2

I´m developing an app which needs to connect to a server to actually work. That means when the server is not working, it should show a message to the user and close the app. Right now when it happens the app throws an IOException, and the app stops working.

The code is:

ConexionHttpPost conexion = new ConexionHttpPost(); //

try {
info = conexion.peticionServer(usuario, latitud, longitud,"A");
} catch (ClientProtocolException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

So what I want is to show a message which tells to the user the server is not working and close the app when ClientProtocolException or IOException happen. I have tried to show an AlertDialog already but it doesn´t work...

Any help? Thanks in advance.

1 Answers1

0

You should not use AlertDialog to show your message. Instead of it you can try an Activity with dialog-theme.

        <activity
        android:name="app.DialogActivity" 
        android:theme="@android:style/Theme.Dialog" >


        <intent-filter>
            <action android:name="app.action.OPEN.DialogActivity" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

        </activity>

I think you've defined your network-connection in a Service, so that you can open this Activity directly:

       Intent i = new Intent("app.action.OPEN.DialogActivity");
       i.setFlags(single|clearTop);//dummy
       i.putExtras(....);//dummy
       this.startActivity(i);
TeeTracker
  • 7,064
  • 8
  • 40
  • 46