Android :: Handle Activity Life Cycle Involving Sockets?

May 30, 2010

I have an Android activity which in turn starts a thread. In the thread I open a persistent TCP socket connection. When the socket connects to the server dynamic data is downloaded. The thread sends messages using Handler-class to the activity when data has been received. Now if the user happens to switch from portrait to landscape mode the activity gets an onDestroy call. At this moment I close the socket and stop the thread. When Android has switched landscape mode it calls onCreate yet again and I have to do a socket re-connect. Also, all of the data the activity received needs to be downloaded once more because the server does not have the ability to know what has been sent before, i.e. there is no "resume" feature.

Thus the problem is that there is alot of data which is resent all the time when landscape mode is changed. What are my options here? Should I create a service which handles the socket traffic towards the server thus I always got all the data which the server has sent in the service. Or should I disable landscape mode all together perhaps? Or would my best bet be to rewrite my server which is a VERY BIG job

Android :: handle activity life cycle involving sockets?


Android :: Activity Life Cycle

Nov 12, 2009

The main activity is running, then there is a interrupt. What was happended, onPause(), onStop() or other change of life cycle? 1. pressed the volume_down key and ringer volume toast occured, the life of main activity will not change? why? 2. short press the power key and the OS sleep,how about the activity ? 3. long press the power key and the phone options appear, how? 4. long press the home key and the tast list appear, how? 5. notifications curtain appear, how? 6. press the back key,how?

View 5 Replies View Related

Android :: Can't Grok Activity Life Cycle

Jun 6, 2010

I am having a really hard time grokking the Activity life cycle concept. The main issue is with onStop() and onDestory() not being guaranteed to be called before the process is killed. I though I had it figured out when I saw that the system calls onSaveInstanceState() when it's shutting down the activity to claim some memory. Thing is that the docs says onSaveInstanceState() will be called before onPause() but how does the system know at this point whether the activity will be killed by the system or the user?

Here is a use case:

1) My activity starts up and is running. 2) At some point I want to show a web page so I use an Intent to start an activity. 3) The web browser covers my app/activity so I would expect onPause() to be called followed by onStop(). At this point it's my understanding that all bets are off and I can be killed at any point without be called. 4) Since the system has enough memory onSaveInstance() doesn't get called. 5) The user presses home and decides to open some app which requires a lot of memory. 6) System wants more memory and decides to kill my app but I am already stopped (onPause() has been called).

View 1 Replies View Related

Android :: Activity Life Cycle - Serialization Taking Too Long

Jul 27, 2009

Finally after many days of getting StackOverflowError, I've tracked down the issue and fixed it, only to find that my game's serialization takes about 5 -10 seconds on the emulator and most likely around that in the target. So far my the lifecycle of my game is as follows

onCreate - check if serialization file exists, if it does, de- serializes it. (~ 5-10 seconds) onPause - if the game is not complete, then serialize it (~ 5-10 seconds) I remember reading somewhere that another activity's onResume will NOT get called UNTIL the previous activity's onPause has ended. So I am worried that my game is delaying another activity that wants to start from doing so i.e like a phone call etc. I think speeding up the serialization is not going to be feasible, so any ideas on what I can do? Can I serialize in the onDestroy instead of the onPause? I read that the onPause is the only safest place to store the state.

View 8 Replies View Related

Android :: Out Of Memory Error On Large Bitmaps And Activity Life Cycle

Jul 24, 2010

I have a scrollable map app which for now has a huge bitmap. It loads fine on startup, but when it looses foreground status and the user brings it backs again im getting an out of memory error. In onPause it trashes the bitmap using recycle, and marks it as null. The onResume checks to see if map==null and will load the bitmap back again, which is crashing the program despite me recycling the bitmap...Here are some bits of code. All of the other references to Bitmap map first check if it is null before loading/drawing..............

View 1 Replies View Related

Android :: Life Cycle - ListActivity

Aug 18, 2010

When my ListView activity loads it creates the Adapter which fills the screen as it should do. Is there an event or way to find out when the Adapter has finished getting enough data to fill the screen. I want to show a spinner the first time the Activity loads and have it go away once the screen has its first load of data from the Adapter.

View 2 Replies View Related

Android :: The Life Cycle Of Static

Mar 7, 2010

When starting a new Activity, I want to pass a complex object and do so by using this approach:

MyActivity.COMPLEX_OBJ = myComplexObj; // which is definitely NOT NULL! Intent intent = new Intent(); intent.setClass(this, MyActivity.class); startActivity(intent);

and then in MyActivity:

@Override public void onCreate(Bundle bundle) { if (COMPLEX_OBJ == null) { // report to Flurry ... } ...

}

View 17 Replies View Related

Android :: Understanding ContentObserver Life Cycle

May 9, 2010

The core of this Widget is an AppWidgetProvider which registers a ContentObserver to the CallLog content URI. This means that my widget is updated every time a call (incoming, outgoing, missed) is recorded. This works fine for a while, until *something happens* and my ContentObserver stops getting called (no error message seen in trace). I would rather that this ContentObserver persisted until the user removes the Widget.

I am guessing that my JVM has been destroyed (due to low memory?), ContentObserver garbage collected and/or ContentObserver unregistered (or just pointing to nothing), but I don't know how to debug this without restarting my code (and thereby re-registering). I can hide this bug by periodically re-registering my Content provider, but I would rather understand the cause and have a more optimal solution..............

View 3 Replies View Related

Android :: Application Object Life Cycle

Sep 30, 2009

When I start my application I prompt the user for the password and use it to instantiate my data adapter object that I will need throughout the application. So I store it in Application object. My activity A prompts user for pwd, instantiates data adapter, sticks it to Application object and later starts activity B which in turn starts the built int gallery activity. When fooling around with gallery and capturing pictures for some time coming back to activity B I discover that Application.myDataAdapter is null. I found out that during me playing with camera the Application.onTerminate() method was called. So it seems like Android killed my process and when B was supposed to become visible it started a process again jumping directly to activity B bypassing A? Is that how it works? Should I then never assume that Application.myField will survive? and init it not only when A is started but whenever I discover it is null?

View 7 Replies View Related

Android :: Understanding Life Cycle When Screen Goes Off And On?

Aug 4, 2010

My device is a Nexus One with 2.2 and I have tested two projects, one on 1.5 and one on 2.1. Problem: I have trouble to understand the life cycle of my application when the screen is turned off and on. Here is my output

// activity starts
08-04 17:24:17.643: ERROR/PlayActivity(6215): onStart executes ...
08-04 17:24:17.643: ERROR/PlayActivity(6215): onResume executes ...
// screen goes off
08-04 17:24:28.943: ERROR/PlayActivity(6215): onPause executes ...
08-04 17:24:32.113: ERROR/PlayActivity(6215): onStop executes ...
08-04 17:24:32.113: ERROR/PlayActivity(6215): onDestroy executes ...
08-04 17:24:32.983: ERROR/PlayActivity(6215): onStart executes .....................

View 3 Replies View Related

Android :: Managing Service Life Cycle Killed Due To Low Memory

Aug 25, 2009

I have a service that polls for data. To indicate this to the user I have a persistent notification in the statusbar. In some cases when the device goes low on memory it destroys the service but OnDestroy is not called. Later when there is available memory OnCreate is called. Is this normal behavior? I had hoped that OnDestroy would be called to I could remove the notification in the statusbar. Now the user thinks that the service is still running, while it has been stopped by the OS.

In order to restart the polling how do I know that the OnCreate is really a restart event and not first time creation of the service? I thought about checking for the presence of the notification in the statusbar, but I couldn't find a API to check if a notification was showing or not. I have not tried "SetForeground" on the service, since the service isn't that important to the user, but maybe that would minimize the problem.

View 4 Replies View Related

How To Make Launcher Have A Long Life Cycle

Jan 2, 2014

My app is a launcher. It gets killed frequently by OS when it running in background. It has to restart and reload data, which taks a long time.How to make it get less chances of being killed ?

View 1 Replies View Related

Sony Ericsson Xperia X10 :: Further Updates After 2.1 - Life Cycle?

Aug 16, 2010

The Xperia X10, X10 mini and X10 mini pro smartphones will all receive software upgrades during their lifecycle to improve performance and add new communication and entertainment experiences. From Q3 2010 onwards, the Xperia™ X10, X10 mini and X10 mini pro smartphones will be upgraded to run on the Android 2.1 operating system in selected markets. The Xperia™ X10's position as the best multimedia Android smartphone will be strengthened through the addition of HD video recording as part of the same Q3 upgrade. A further upgrade to the Xperia™ X10 in Q4 will make it possible to connect wirelessly to and display content on your television and enhance the Timescape™ and Mediascape applications..................

View 2 Replies View Related

Android :: Handle Screen Orientation Changes With An Activity Started Within A Tab's Activity

Nov 2, 2010

I have a TabActivity, and each Tab corresponds to its own Activity. In one of them, in the onCreate method, I use startActivityForResult to show a dialog (specifically, Bump's BumpAPI activity).

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

The problem is that when the screen orientation changes, it tries to create the tab's activity again which makes another BumpAPI dialog, resulting in multiple stacked on top of each other. Do I have a hook into the started activity to cancel the previous one when the orientation changes?

A workaround seems to be to add a button that when clicked, starts the second activity, but that adds an unnecessary step.

Also, I can't fix the screen orientation for the entire tabActivity because some of them require typing and users may want to use their physical keyboards.

View 1 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 :: Handle Existing Instance Root Activity Launching Root Activity From Intent Filter

Apr 3, 2010

I'm having difficulties handling multiple instances of my root (main) activity for my application. My app in question has an intent filter in place to launch my application when opening an email attatchment from the "Email" app. My problem is if I launch my application first through the the android applications screen and then launch my application via opening the Email attachment it creates two instances of my root activity. steps: Launch root activity A, press home Open email attachment, intent filter triggers launches root activity A Is it possible when opening the Email attachment that when the OS tries to launch my application it detects there is already an instance of it running and use that or remove/clear that instance?

View 1 Replies View Related

Android :: How To Handle Activity When Orientation Changes?

Aug 9, 2010

I am writing an activity, that loads data from a server and displays it as a list using ArrayAdapter. For that I'm showing a progress dialog i.e loading, while it loads all data from the server. Then i dismiss the dialog in a handler. My problem is that when ever i change the orientation, the progress dialog is again shown, which is not needed, because all the data is displayed already?

View 1 Replies View Related

Android :: How To Handle Home Key In Our Activity

Sep 8, 2010

How to handle Home key....Plzz Help me out.We can handle Home button.if you have seen the Nexus One device...when u reset the phone ..and switch it on again some tutorials kind of thng comes..at that time wen u press the home button its not taking u to the Launche Activity...if its not possible then how they are handling over there.I want the Answer..No one in this Blog has any idea how to handle it....or no one has tried on this..sum are sayng that we can handle it by PhoneWindowManager.java class,some r sayng we can handle it by Using onNewINtent() method.But the Question is how we can handle it by these two ways...Just provide me the sample code..where we are handling the HomeKey.

View 9 Replies View Related

Android :: How To Handle Notifications In An Activity

Sep 13, 2010

I have an Activity that will query a RESTful API every x seconds (polls using a handler). The results of the GET are used to update a ListView. This is done using an AsyncTask.

I want to put a Notification in the Notification bar when certain criteria are met in the new data. Everything I have read up to this point has suggested that notifications should be created and updated using a service so that the notifications can be made even when the application isn't in focus. I see the positive aspects of this.

However, I'm unsure if I should just create a service from within my activity or if I need to do something more complex than that. I'm undecided on if I should scrap my AsyncTask model in favor of using the Service to update my list view.

So, my questions are:

1) Is there a good tutorial showing how to make a local service from an activity?

The tutorial doesn't need to show how to make them communicate, the service could be isolated from the main activity.

2) Will #1 provide me with the notification benefits I'm looking for? (Notifications are generated even when the main app isn't visible)

3) Should I use this same service to update my listview?

The service would basically be making the same query that the AsyncTasks are, just doing different things with the results. The app would seem to make more sense to have the Service query, do notification processing, then give the results to the activity, but I haven't found a good resource that clearly demonstrates how to do something like this.

View 1 Replies View Related

Android :: Activity Found To Handle Intent?

Aug 4, 2010

I am tring to invote internal media player of android from my activity. Seems there is some problem in menifest file .

Please look into this issue .

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

View 2 Replies View Related

Android :: Activity Not Found To Handle Intent?

Nov 24, 2010

I have a problem regarding my intent. It seems that my app crashes when i select the intent. I found the line of error code due to the stack trace. But i couldn't find anything wrong with it. Hope anyone can help me with this.

This is the java code in line 121:

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

This is the stack trace:

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

View 2 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 :: ActivityNotFoundException: No Activity Found To Handle Intent

Nov 2, 2010

test.class type is right? How to? What should I do?

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

View 2 Replies View Related

Android :: Handle Background Threads When Leaving An Activity?

Oct 10, 2010

I need my Android app to save it's state to disk when its activity is put in the background or killed. It's been suggested that I start a thread when onPause() is called and perform any expensive I/O procedures there (see http://stackoverflow.com/questions/3894668/saving-loading-document-state-quickly-and-robustly-for-image-editor).

In what situations will the OS kill the thread and how commonly do these situations occur?

I assume it will be like how Activities are dealt with where the OS can arbitrary decide to kill the thread but will mostly only do this when resources are extremely limited. It would be nice to find some specific documentation of this though.

From playing around, with some test code, a background thread started in onPause() will run indefinitely in the background on my device (I tried loading lots of apps and couldn't get it to be killed).

For my specific app, I'm writing a bitmap editor where I'm using the Command pattern and the Memento pattern to allow undo and redo of edits. I'd like the user to be able to undo/redo their edits even e.g. the user gets a phone call and the activity is killed when it is put in the background. The best solution I can think of is to use a background thread to constantly save my command and memento objects to disk during application use and to finish up saving any objects that are left in a background thread if onPause is called. In the worse case, if the thread is killed I'll only lose some edits.

View 3 Replies View Related

Android :: Handle Lock Screen Button Input For Droid Activity?

Nov 12, 2010

Suppose I have something like an alarm activity which launches the alarm through the lock screen, accomplished via

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

Now, from here I could press the back button to kill the activity, but I also want a press of the lock button to silence the alarm. How would I go about creating a handler for presses of the lock screen button?

View 2 Replies View Related

Android :: Why Return Null When Using FindViewById In Activity To Find And Handle CustomView?

Dec 4, 2009

I wrote CustomView Class, and load it in layout. so i trid to find CustomView using findViewById() in activiy to get handle. but findViewById() was return null.

Written Code is like below:

CODE:.........

MapCanvas.java:

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

View 2 Replies View Related

Android :: Appbrain - Involving Email Address?

Jun 5, 2010

i have two email addresses, one is my fullname@gmail.com which i use for private "serious" stuff like bank account logins, personal email to freinds/family, facebook, etc. and then i have my "internet" email which is my screenname@gmail.com which i use for forum signups, craigslist entries and for fun pretty much.

question is, when i get my android phone, do i have to assign an email address to the phone? when i tried to sign up for appbrain it asked me to log into my gmail account but i wasn't sure which one i would use.

is it pretty much provide a gmail address then do whatever you want? i justdon't want my private email address to be compromised in the future.

View 2 Replies View Related

Android : Add Button And GLSurfaceView / Done Without Involving Xml Layout?

Aug 27, 2010

I have a GLSurfaceView where I show some animations using OpenGL.

I now want to add a button to this view. How is this accomplished?

Can it be done without involving the xml layout?

View 1 Replies View Related

HTC EVO 4G :: Have Any Battle / Horror Stories Involving Your Evo?

Aug 10, 2010

Have any battle/horror stories involving your Evo? I just got mine replaced on friday..and i was walking down our outside stairs yesterday, and dropped it. "luckily" it hit the bottom left corner, and indented it. Oh well, it happens.

View 2 Replies View Related

Android :: No Activity Found To Handle Intent - Act - Android.accounts.AccountAuthenticator

Jun 28, 2010

I'm trying to have my app display my login activity when a user selects add account in accounts&sync or wants to use the app and isn't logged in yet. I've followed the example SampleSyncAdapter fairly closely, but can't get it to work.

In my auth service:

CODE:........

In my manifest:

CODE:........

In my main activity:

CODE:.......

I've tried doing both

CODE:.......

And

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

Before the startActivity() call, but it still can't find an activity for that intent. If I try to add an account via accounts&sync the app crashes with the same ActivityNotFoundException.

I've examined c99's last.fm app, which defines a custom action and uses intents based on that action rather than android.accounts.AccountManager.ACTION_AUTHENTICATOR_INTENT. Is that a better approach? Is there a way to make it work with Accounts & Sync?

View 1 Replies View Related







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