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 8996953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:49:23+00:00 2026-06-15T23:49:23+00:00

I’m making Android Jabber chat client for school’s work. Everything works okay so far.

  • 0

I’m making Android Jabber chat client for school’s work.

Everything works okay so far. But when I change the phone’s orientation it will re-connect to server.

It only took 3-5 seconds to re-connect, but during that time if I send a message, it will cause NullPointerException which is the XMPPConnection variable.

By googling, I found that I can use onRetainNonConfigurationInstance but my ChatClient class extends Fragment and it’s not available.

My target is 4.0.3+ so I don’t need to worry about compatibility support or such.

Any solution except using static variable?

Thanks

  • 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-15T23:49:24+00:00Added an answer on June 15, 2026 at 11:49 pm

    I am not sure that hosting your xmppconnection inside the fragment is a good idea.

    A common approach would be to host it inside a service so your connection can persist even if the application is in background (and in any case does not depend on your activity / fragment recreation), or, if you are not interested in having it connected when your app is in background, another good option would be to have the xmppconnection hosted inside a singleton object.

    If, on the other hand, this is a school project and all you want is the fragment persist along configuration changes such as rotation, you can use
    setRetainInstance method:

    Control whether a fragment instance is retained across Activity re-creation (such as from a configuration change). This can only be used with fragments not in the back stack.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I want to construct a data frame in an Rcpp function, but when I
I'm making a simple page using Google Maps API 3. My first. One marker
I need to clean up various Word 'smart' characters in user input, including but
Let's say I'm outputting a post title and in our database, it's Hello Y’all

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.