Android :: Activity Lifecycle And Static Variables

Jul 14, 2009

I just ran into a situation where it looks like a static variable reference is persisted across activity sessions. I didn't expect that because I thought that when an activity exits, it's de-referenced and garbage collected. I am wondering if anyone can shed some (more) light on when the VM eliminates object references for Activities and Services and in particular when static variables get reset to default values?

Android :: Activity lifecycle and static variables


Android :: Need To Use Static Variables In Droid

Mar 19, 2010

In android, are using static variables a recommended practice?
E.g, implementing a Singleton pattern in Java, I usually do...

Also, when does this get cleaned up by the Android JVM?

View 6 Replies View Related

Android :: Alternatives To Static Variables In Droid?

Jun 17, 2010

I am using static Arrays and HashMaps to store some values in my AppWidgetProvider class. But they are becoming null when the process dies, so the widget does not work anymore. Are there any alternatives to using static members to store data for an AppWidgetProvider in Android?

View 5 Replies View Related

Android :: All Static’s Variables Retaining Values When Launching Again

Dec 1, 2009

I have been facing problems to manage statics variables used in my android application. If we exit the application against a particular event (touch or key event -which is must for my app), all the statics variables are retaining the values when I am launching it again. I am invoking Activity.finish() method for termination . I know there is a collection type class available called Bundle and we can use it to save the states of all the statics and get those back when again creating the same activity during relaunch, but it would be a hard task if we want to port some j2me applications to Android because of having thousands of statics variables. Is there any way to kill the application completely including all the statics variable used there?

I tried with System.exit(0) and it works well for Android G1 and G2 (tested in firmware 1.6). But in Android Robyn (prototype) the same causes a major defect ("Activity not responding" popup apears just after exit) and I came to know from android dev forum that calling System.exit(0) is not recommended for termination of an activity.

View 3 Replies View Related

Android :: Parsing XML And Initializing Static Variables Of Some Class

Dec 21, 2009

I have an application that is driven by a configuration XML: various app properties are loaded at the app start-time by parsing the XML and initializing static variables of some class. The data read from this XML drives different Activities of the application. Presently, I have called the "parsing and the properties-initialization" from the onCreate() of my Main Activity. I have a few questions as regards this case/approach: Should I invoke the app initialization method from the Application Object or is the current approach correct?

What advantages/disadvantages do/would we get/have if I choose to invoke it from the Application object? Do we really need a static class to store app properties? Or can we have all the properties as a static Collection variable in the application object? Parsing a XML(~200 nodes) at app load time might take some time (not sure how long tho); How can I avoid the dreaded ANRs? I am using a Pull Parser.

View 2 Replies View Related

Android :: Static Method In Java Accept Only Final Or Non Final Variables Within Its Method - But Not Static

Sep 15, 2010

Why should a static method in java accept only final or non final variables within its method, but not static?

For example I have the following method:

CODE:.................

View 6 Replies View Related

Android :: Static Variables Of An ApplicationContext Subclass Left Untouched When The Process Is Killed?

Sep 7, 2010

Do static variables of an ApplicationContext subclass left untouched when the process is killed?

View 4 Replies View Related

Android :: Android Static Object Lifecycle

Dec 22, 2009

I am creating event search application, we set search criteria from one screen populate in another screen then user can edit search criteria from 3rd screen and goes to 4th screen.To achieve above task i am using static object which remember the values around the application and i don't need to do any thing extra.But i am afraid if about static object life cycle in android if low memory found android delete static objects?As android supports multi tasking, if user switches to another application and when user comes back application start acting crazy, does static object get removed when it multi task?and also suggest holding static object via singleton method is better approach?

View 2 Replies View Related

Android :: Activity Lifecycle OnStart OnStop Possible?

Oct 5, 2010

In the Android Application Fundamentals it says that after the call to the onStart()-method of the activity lifecycle either the callback method Resume() or onStop() is called. In case of an "normal" Start of an activity the system calls onCreate(), onStart(), onResume().But does somebody know an example where onStart() - onStop() are executed one after another?

View 2 Replies View Related

Android : Activity Lifecycle Cause Memory Leaking

Aug 7, 2009

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

The Activity Lifecycle could have implementation and or design bug: One case is to initialize a big image in onCreate(), try to reuse the image during the whole lifecycle, and then recycle the image in onDestroy(). Test showed that onCreate() is called every time one navigate away from the activity and back again, but onDestroy() is not called at all. This behavour causes memory leaking for the big image (size 960*1920). After 6+ times away and back to activity, the system runs out of memory and has to kill the process.

One workaround is to initialize the big image in onResume() and recycle in onPause(), but that's not so good reuse.

Could it be better to change the process (as shown in the diagram) a little bit such as: Call onDestroy() first when a process is killed?

View 3 Replies View Related

Android :: Activity Lifecycle On Nexus One - OnStop Not Called

Mar 4, 2010

I have a problem with the activity lifecycle specifically on Nexus One (2.1 running on emulator works fine). If I just create a simple empty Activity with no special launchModes that logs the calls on the onStart and onStop methods, this is what I see: - launch app: onStart called; - home button: onStop NOT called; - launch app: onStart NOT called; - home button: onStop NOT called: and so on. Sometimes if I press the back button then the onStop is not called, but the when i launch the activity again the onStart is called and right after the onStop is called. Similar results with different launchModes. What is going on? Can anyone confirm this?
i found an android issue for the problem here: http://code.google.com/p/android/issues/detail?id=6094 and a similar thread here http://groups.google.com/group/android-developers/browse_thread/threa.

View 24 Replies View Related

Android :: Rule That Relates OnMeasure To The Activity Lifecycle

Jul 12, 2010

I have a custom view on which I need to call a method from my activity after the view has been measured in onMeasure. I would like to know exactly when onMeasure is called in the View layout process. It looks like onMeasure is called after my activity´s onCreate, onStart, and onResume. I could override onMeasure and maintain a variable that contains whether the view has been measured or not. However it would be nice to know if there is a rule that relates onMeasure to the activity lifecycle?

View 4 Replies View Related

Android :: Using Activity Lifecycle Methods / What's Best Strategy For Binding?

Sep 15, 2010

I'm binding to a local Service (that is, not using IPC and AIDL) from several activities. I want to ensure that I'm not holding references to this service from activities that the user isn't using. My options are: 1.) to bind to the service in onCreate() and unbind in onDestroy(). 2.) bind in onStart() and unbind in onStop(). 3.) bind in onResume() and unbind in `onPause(). Or some combination of these. Which is the best-practice way of binding and unbinding to a local service? Do I not need to be concerned with holding local connections from stopped activities? Additionally, once bound to this particular service I am retrieving a Cursor which is attached to my ListActivity via a CursorAdapter. The data retrieved by the Cursor may have changed while the Activity was out of view so I want to requery it when the Activity is shown again. If I bind in onCreate() I can requery in onRestart(). If I bind in onResume() each time the data will be fresh because I'll query it in the Service's connected callback.

View 1 Replies View Related

Android :: How To Handle Activity Lifecycle On Wake Up - Alarm App

Oct 4, 2010

I'm having a couple of problems with an alarm app I am developing.

The first thing that I think is a bit weird is that when an alarm goes of and wakes the phone up. These things happend.

oncreate
onresume
onpause
onresume

Why are they run in that order? The last two should not be called? And this is what's causes me big trouble, because when i press home or back on the phone, onPause is run, which I want to call finish() from. And that part works as it should, but that does not work when the phone wakes upp from sleep bacause of the onPause call...

View 2 Replies View Related

Android :: Get Information Of Activity Lifecycle Callbacks In Views Drawn?

Aug 3, 2010

I want to get the size of a view that is in my activity but I am not able to get that information in any of the activity lifecycle callbacks (onCreate, onStart, onResume). I'm assuming this is because the views have not been drawn yet. At what point are views drawn and is there a callback I can put my code so I can get the size of the view?

View 2 Replies View Related

Android :: Activity / Process Lifecycle - Save / Load Data To / From Disk

Nov 26, 2009

My app is made of two activities, A and B. I'm considering this sequence of steps: Activity A is started. A launches B [A is paused, B is running]. B launches a map intent [A and B are both paused now]. Now the user is using the maps application and the system decides it needs more memory. Can the system kill only one of my activities for memory, or will it always kill all activities in a "process" in this situation?

Both activities share some static data like:

class Data {
public static String mName;
public void save() {
// write to file: mName;...................

View 1 Replies View Related

View Lifecycle And Refresh When Returning From Activity?

Oct 26, 2012

I'm writing an application for Android and have multiple Activities, there are three to be exact. When a user drills down to the record they would like to view, they can modify it.

The issues is that when I click the back button to move to the previous screen, i'd like to refresh it to reflect the update performed by the end user. I can't figure out how to hook onto the appropriate event and then refresh my data on that view.

View 3 Replies View Related

Android :: Previous Set Instance Variables Null When Activity Resumed

Apr 20, 2010

I am using an Application object to store app-wide instance data--data that I need to remain in existence for the entire lifetime of the app, so the Application class seems like the proper place to put it. I have just finished reading this thread http://groups.google.com/group/android-developers/browse_thread/threa... that goes into pretty good detail and receives confirmation from Googler hackbod as to how the Application class performs--and from that info it seems this strange behavior I am receiving should not be happening...

Basically, every once in a while when I resume my app in any of its Activities (it is still running in memory so onCreate is not called) I get NullPointerExceptions because instance variables in my Application class are returning null when I request them from my Activity (via a getter method in my custom Application class). It seems as if sometimes Android saves the states of my Activities but deletes all my instance variable data... This can't be an Android problem--there must be something wrong with my code.

Has anyone else ever ran into an issue of this kind? Any ideas as to what may be causing this? I'm not going to post my code here as that won't help anyone, but hopefully someone can point me in some helpful directions.

View 11 Replies View Related

How To Pass Variables From Service To Activity

Aug 30, 2012

how can I pass variables from service to activity and vice versa?

View 1 Replies View Related

Android :: Detailed Android Activity Lifecycle - OnAttachedToWindow()

Jun 14, 2010

I'm interested in android activity lifecycle and I would like to get more detailed description/documentation/reference than widely available basic (onCreate->onStart->onResume) one.

My need comes from realizing that starting new activity (Theme.Dialog styled) from onAttachedToWindow() greatly improves response time if comparing to starting it from onCreate(). I wonder how this onAttachedToWindow() fits into whole android activity lifecycle. Official API ref description "Called when the window has been attached to the window manager" doesn't help a lot.

View 1 Replies View Related

Android :: Static Layout For Whole App That Must In All Activity

Nov 17, 2010

Static Layout for whole app that must be in all Activity

View 12 Replies View Related

Android :: Use Of Static Finals In Activity

Sep 8, 2010

Why is the use of static final variables encouraged to declare constants over just final variables? The use of static sounds logical when there will be many instances of a class but is this argument correct when used for a Android activity. In fact, since the Class instance will be around even after the activity finishes and is eventually garbage collected, it seems like all these constants will still be in memory until the class loader is around. Also, does the compiler inline non-static final variables(ints and String) just like it does for static final variables?

View 2 Replies View Related

Android :: Static Database Class To Use With Any Activity

Jan 5, 2010

I am new to Android, and I haven't developed any app regarding databases on Android yet. So I have a few basic questions. I am after a good database class sample, that will let me to run the CRUD operations. I would like to use it as a static class

like: clsDB->Select("select * from clients");
or objClient->Delete(clientid);

I am wondering if someone, can share his database classes, if more people share the best. Also I have in mind to reuse this class in multiple ways, I will have services, activities etc...

View 4 Replies View Related

Android :: Avoid Non Static Inner Classes In Activity?

Jun 17, 2010

Since I seem to have caught two activity references in a heapdump, where the Activity is set to singleTask. Romain's advice on avoiding memory leaks includes: "Avoid non-static inner classes in an activity if you don't control their life cycle, use a static inner class and make a weak reference to the activity inside"

What does this mean exactly? I can't find any examples, positive, or negative for this rule. I do have some non static inner classes in my activity. Most of them are anonymous inner classes like this one. I see hundreds of them in the samples:....................

View 24 Replies View Related

Android :: Remove Static Variable Value , When Will I Close My Activity?

Aug 26, 2010

I want to clear variable value when will i close activity.

View 1 Replies View Related

Android :: Create Static Options Menu For All Activity Screens

Jan 15, 2010

I wanted to create a static options menu for all my activity screens. I dont want to override onCreateOptionsMenu() in each activity. Since Menu class is an interface with a huge number of methods, its difficult to create a static object of the implementing class.

View 3 Replies View Related

Android :: Static Fields In Activity Classes Guaranteed To Outlive Create / Destroy Cycle?

Oct 28, 2009

I frequently run into the problem that I have to preserve state between several invocations of an activity (i.e. going through several onCreate()/onDelete() cycles). Unfortunately, Android's support for doing that is really poor. As an easy way to preserve state, I thought that since the class is only loaded once by the class loader, that it would be safe to store temporary data that's shared between several instances of an activity in a static Bundle field. However, occasionally, when instance A creates the static bundle and stores data in it, then gets destroyed, and instance B tries to read from it, the static field is suddenly NULL. Doesn't that mean that the class had been removed and reloaded by the classloader while the activity was going through a create/destroy cycle? How else could a static field suddenly become NULL when it was referencing an object before?

View 2 Replies View Related

Android :: Call Non Static Method In Static SQLiteDatabase Class

Mar 30, 2010

i want to display a msg to the user (msg box or Toast) when exception happend in a static SQLite Database class that i use. the problem is that i cant call a non static method in a static class , how can i handle this. this is the class

private static SQLiteDatabase getDatabase(Context aContext) {

and i want to add something like this in the class when exception happen but context generates the problem of reference to non static in static class.

Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();

View 1 Replies View Related

Android :: Cannot Make Static Reference To Anon-static Method

Feb 7, 2010

I'm having some issues with the old "Cannot make a static reference to a non-static method" error in my Android program. I am creating a sand falling game (similar to the Powder Game) and I created a class called Control to create a Control Bar at the bottom of the screen with a slider for brush size (that works fine) and a button to pop up a Dialog to allow users to pick the selected element. However, when I call DemoActivity.showDialog(2) from my code, it gives the static reference to non-static error (DemoActivity is the main activity of my application). I also tried changing it to just Activity.showDialog(2), but I got exactly the same error!

Here's my code:

CODE:................

I fixed it by adding the following to my Control.java code:

CODE:..........

And then calling control.setActivity(this); from my onResume section of DemoActivity.java!

View 2 Replies View Related

Android :: Non-static Method Cannot Be Referenced From A Static Context

May 26, 2010

I am modifying the source code here: http://thinkandroid.wordpress.com/2009/12/30/getting-response-body-of-httpresponse/

I get this error:

code:.............

This error is line 13 on the second box.

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved