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

  • SEARCH
  • Home
  • 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 9172887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:27:38+00:00 2026-06-17T16:27:38+00:00

I have three questions:- 1) I am creating an OPCUA client for an OPCUA

  • 0

I have three questions:-

1) I am creating an OPCUA client for an OPCUA server. My Application has several avtivities, and most of them need the connected client. What is the best way to make my connected client available in all my actvities. I have currently used a static variable to hold my client. But is there any other better way. My client is not Serializable or Parcelable and thus cannot be passed as an intent argument.

2) Can I maintain this static variable in a Service and access the same in all my activities with MySerivce.connectedClient? Would that be good programming practice?

3) What if my application force closes and the connection with my server is not released. I want to be able to disconnect from my server even if my application force closes. Is there a way to ensure this (except for enclosing all my code in a try catch block) ?

Please suggest.

  • 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-17T16:27:39+00:00Added an answer on June 17, 2026 at 4:27 pm

    Its better to keep all application specific things in Application class.

    http://developer.android.com/reference/android/app/Application.html

    eg-

     public class XYZ extends Application {
     .....
    
     }
    

    All the app specific initialization could be used here too.

    For your requirement , Static initialization fits here well. The only thing is that It can be done in Application class rather than a Service ( which is prone to be killed by android )

    Force stopping the app will kill the entire process (i.e. with Process.killProcess(int pid)). All resources associated with the application will be removed and freed by the kernel. So no, there is no way that you can intercept this action.

    but for safer side always

    1) You should unregister the server connection in OnDestory ()

    2) Even for more safer you can use following functions in Application class

    public void onLowMemory ()
    public void onTerminate ()
    public void onTrimMemory (int level)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 questions for you. Im creating an Application for Chat that relies
Hopefully two simple questions relating to creating a server application: Is there a theoretical/practical
There have been several questions posted to SO about floating-point representation. For example, the
There have been several questions over the past few days about the proper use
I have some crash in a test application I'm creating and I'm pretty sure
In my application I have three view controllers of concern. The first contains a
I have several questions about the PE subsystem field, which may overlap to some
I have three models: class Client < ActiveRecord::Base has_many :balancesheets has_many :investment_assets, :through =>
Im a newbie PHP programmer and I have a few questions about creating a
I have an iPad application with multi-threading capabilities using GCD. When i need to

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.