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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:18:24+00:00 2026-06-15T17:18:24+00:00

My Android app comprises several activities: M (main or root), A , B ,

  • 0

My Android app comprises several activities: M (main or root), A, B, C…
Below is a possible activity navigation graph:

enter image description here

When my root activity M is being initialized, I cache some parameters (like screen dimensions) as static variables in special class MyUtils to use them later in other activities.

The Kaboom happens when I press Home button in activity say C and then launch a dozen applications. When I return back to my application, it appears that everything has been destroyed. C.onCreate method is being called, but cached parameters appears to be reset.

I would like to start from M, not from C after Android has devastated my application after a long pause. How can I achieve this?

I thought of something like this:

// to be put into all my activities but M:
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (MyUtils.GetScreenWidth() == -1)
    {
        // seems like Android killed my app
        finish();
        return;
    }
    // Normal initialization.
    // Use MyUtils.GetScreenWidth() to align my ui elements.
}

…but I’m not sure that it’s the best way. What would you 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-15T17:18:25+00:00Added an answer on June 15, 2026 at 5:18 pm

    To be honest, I would do the same or something similar to what you’re doing. A possibly better idea is to have a static MyUtils.initialize() method, perhaps taking in an application context parameter, that is called at each onCreate() of each Activity that uses MyUtils.

    Either that, or store the values each in a SharedPreference.

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

Sidebar

Related Questions

my android app crash before load main.xml. This is the exception thrown java.lang.RuntimeException: Unable
I have created three Activities for an Android app: BaseballCardsList, BaseballCardsDetails, and FilterBaseballCards. BaseballCardsList
I have an android app with a screen that comprises of a ListView, which
My android application compirises two Activities: .MainActivity and android.app.NativeActivity. The latter is implemented purely
The android app reads from database but doesnt write anything to DB, the app
My android app leaks, what should I check? I gave a look at avoiding
My android app is taking more and more memory over time. I took a
My Android app looks great at 480x800 pixels resolution but it breaks at LDPI
My android app requires that the device has an SDcard and that SDcard is
My android app has a two word app name, and the 2nd word doesn't

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.