Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8364457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:26:08+00:00 2026-06-09T12:26:08+00:00

I implemented an Android Application with following features: Application: public class ApplicationGlobalAgent extends Application

  • 0

I implemented an Android Application with following features:

Application: public class ApplicationGlobalAgent extends Application contains:

  • a MainActivity: to display GUI drawing -> and start other activities from it.
  • a network ServerSocket and a client Socket: to send/receive data in duplex mode.

I want to terminate Application when MainActivity finish, I did as follow:

In MainActivity extends Activity:

@Override
public void finish()
{
    super.finish();

    Log.d(DEBUG_TAG, "finish and call app termination");

    //call the application to terminate
    getApplication().onTerminate(); 
}

In ApplicationGlobalAgent extends Application:

@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());
}

BUT results are:

When have no network connection, the application terminates successfully, otherwise "Terminated!" is never printed until I close the network sockets at other side (who connected to the Android sockets).

So, How can I force the application to properly and fully terminate when exit the MainActivity with connecting network sockets?

Appreciate all your helps!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:26:10+00:00Added an answer on June 9, 2026 at 12:26 pm

    @Override public void finish()

    You should be overriding onDestroy instead.

    getApplication().onTerminate();

    Never call this directly.

    System.gc();

    This really isn’t necessary.

    android.os.Process.killProcess(android.os.Process.myPid());

    Why are you having the application call killProcess on itself? You should let the Android runtime system kill processes for you.

    How can I force the application to properly and fully terminate when exist the MainActivity with connecting network sockets?

    You don’t need to worry about clean-up unless you have allocated resources that wouldn’t be cleaned up when the Java process is killed by the kernel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I implemented Android service for listening user location: public class ListenLocationService extends Service {
I've been following book about Android testing and implemented this sample: public class TemperatureConverterActivityTests
In our Android application I implemented the contact selection by using Intent action *ACTION_PICK*
I've implemented application state saving/loading in onSave/RestoreInstanceState and onCreate in one of my android
I am working on an android application in which i have implemented voice recognition
I have implemented one application in android which uses epublib to view .epub files.
I am trying to implement following thing in android 2.x. In my application i
I have implemented an Augmented Reality application on Adobe Air for Android. When I
i am new programmer in android application i would like display multiple notifications one
I implemented the following TextView in a RelativeView: <TextView android:id=@+id/textView1 android:layout_width=wrap_content android:layout_height=wrap_content android:layout_alignParentRight=true android:layout_alignParentTop=true

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.