Android Application data should not be released by android OS

public class MYApplication extends Application {
   String property;

setter getter


does above code make sure property will not be collectied by android OS if not used for a long period of time.

Asked by: Blake711 | Posted: 24-01-2022

Answer 1

No. Android reserves the right to kill any application at any time if it feels the need. Even foreground processes can be killed if the device gets low on memory. This means the Application object will be destroyed and all its attributes lost.

The only way to ensure your application's transient state never gets lost is to respond appropriately to the lifecycle events Android offers, or just store values persistently.

If you want to store a String for your application why not use Preferences? This means the value would be never be lost, even if the device is switched off.

private static final String PREFERENCE_MYSTRING = "mystring";

static String getProperty(Context context) {
    return PreferenceManager.getDefaultSharedPreferences(context)
        .getString(PREFERENCE_MYSTRING, "");

static void setProperty(Context context,String value) {
        .putString(PREFERENCE_MYSTRING, value)

(I'm not quite sure what getter and setter are in your code sample, but I don't think that's relevant.)

Answered by: Adelaide751 | Posted: 25-02-2022

Answer 2

As I understand it, it's central to override onDestroy() if you want to prevent Android OS from killing your process.

Answered by: Ned580 | Posted: 25-02-2022

Similar questions

how to upgrade my custom android application which will not be released to the Android market?

I tried several links but no one has given any appropriate answer. Scenario is something like : I have my custom .apk file with version 1.0(let's say) which is already installed in android device(we are not using Android market to install it) and later point of time we have to release the same .apk file with some fixes of application bugs. So is there any possible way to upgrade pre-installed android application wi...

java - Android Application will auto update when a new version is released on play store

I update the new version of my application in play store. Want to make auto update in those phone where the application is already installed. I did this work. dependencies { compile 'org.jsoup:jsoup:1.10.2' } and in MainActivity I did this work- public class MainActivity extends AppCompatActivity { String newVersion; @Override protected void...

android application memory leaks

I am using kind of results search engine, problem is to remember the searching criteria i made singleton static class which keeps only one instance. In my application there are lots of class level private variables, lots of public static variables, a big util class which contains only static final methods. problem is my application get crash any time any where any spot and interesting thing is crash code a...

Android Email application - Is it possible to get all the details which are configured in Email application

Is there any way to get in the code: Email id Password SMTP host SMTP port which the user used to setup his Email account with the Android built in Email application Required because, I am written a MailSender class using JavaMail API there I need to send the mail using the details what user configured in Built in Android Email application.

Android Intent for Twitter application

Is it possible to show a list of applications (with intent.createChooser) that only show me my twitter apps on my phone (so htc peep (htc hero) or twitdroid). I have tried it with intent.settype("application/twitter") but it doesnt find any apps for twitter and only shows my mail apps. Thank you, Wouter

webserver - Retrieve data from a web server for android application

I am developing an application that needs to retrieve some data from a web server. But I have no idea how can this be possible?

Should a legacy Android application be rebuilt using SDK 2.1?

I have an Android application that uses the well known Strategies for Legacy Applications. It is build with the Android SDK 2.0 with manifest settings minSdkVersion="3" (API 1.5) and targetSdkVersion="5" (2.0). Question1: Since maxSdkVersion is not specified, the application should be...

android - Intent to pick an installed application slow in my activity, why?

If you long press on your homescreen and pick to add an application shortcut, you will be greeted with a listview showing all of your instal applications. I needed this same functionality in my application so I copied the intent from the launcher source: Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); Intent pic...

web services - How to store data accessible to both a web site and android application?

I’m developing an Android and web application that will function as a service (use the same data). My question is how should the data be stored to allow for both the web and the android application to have access to the same set of data? Should the android application connect to the sites MySQL server to store/access data? If so how do I allow someone to access the data when they are not in ...

Android 1.6 SMS (older application code)

I have HTC Tattoo with Android 1.6. I have maed a Java program for SMS sending. I got the source on the Internet, I think, versions before 1.6. The problem is: SMSs are sent twice. What is a possible cause for this problem? If possible, please simply post sample code what works OK.

How to close Android application?

I want to close my application, so that it no longer runs in the background. How to do that? Is this good practice on Android platform? If I rely on the "back" button, it closes the app, but it stays in background. There is even application called "TaskKiller" just to kill those apps in the background.

listview - android application failing upon user scrolling - no 'obvious' error

I'm having a strange problem with Android 1.6 I have an application that has a ListView (found in Activity #1). The user can click on one of the rows in the ListView and is taken to a 2nd Activity (Activity # 2). User can then use the back button to go back to the ListView. The problem is that if the user scrolls down the list after returning from Activity # 2 the application crashes, bu...

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android