Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to properly terminate Android application with live sockets
    primarykey
    data
    text
    <p>I implemented an Android Application with following features:</p> <p>Application: <code>public class ApplicationGlobalAgent extends Application</code> contains:</p> <ul> <li>a MainActivity: to display GUI drawing -> and start other activities from it.</li> <li>a network ServerSocket and a client Socket: to send/receive data in duplex mode.</li> </ul> <p>I want to terminate Application when MainActivity finish, I did as follow:</p> <p><strong>In MainActivity extends Activity:</strong></p> <pre><code>@Override public void finish() { super.finish(); Log.d(DEBUG_TAG, "finish and call app termination"); //call the application to terminate getApplication().onTerminate(); } </code></pre> <p><strong>In ApplicationGlobalAgent extends Application:</strong></p> <pre><code>@Override public void onTerminate() { // do close ServerSocket and client Socket in networking threads mNetworkManager.DoStop(); System.gc(); Log.d(DEBUG_TAG, "Terminated!"); super.onTerminate(); //?? should be placed at the end of functions ?? //totally kill this application process android.os.Process.killProcess(android.os.Process.myPid()); } </code></pre> <p><strong>BUT results are:</strong> </p> <p>When have no network connection, the application terminates successfully, otherwise <code>"Terminated!"</code> is never printed until I close the network sockets at other side (who connected to the Android sockets).</p> <p>So, How can I <strong>force the application to properly and fully terminate</strong> when exit the MainActivity with connecting network sockets?</p> <p>Appreciate all your helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload