Android :: Close Cursor When Activity Is Stopped Or Pause
Sep 10, 2009Just wondering is it necessary to close cursor when an activity is stopped or pause?
View 5 RepliesJust wondering is it necessary to close cursor when an activity is stopped or pause?
View 5 RepliesIf I pass a cursor to a simplecursoradapter, do I still need to close the cursor? if so when: after I pass it to the adapter or when the adapter is finished?
View 2 Replies View RelatedIf I don't close() a cursor explicitly, relying on gc instead, may it, theoretically, cause any problems?
View 2 Replies View RelatedI supply a cursor to a ListActivity like this: My question is how/when should I close my cursor when I am done? Cursor cursor = get ContentResolver().query(uri, null, null, null, null);
if (cursor != null) {
mCursorAdapter = new CursorAdapter(this, cursor);
setListAdapter(mCursorAdapter);
I see no means by which my activity can pop itself off the activity stack to return the user to the one he was using before it was invoked. Is there one? My purpose is that my app has some data structures built from data provider queries that take 5-15 seconds to assemble and I don't want a lot of latency if it is used in a few one-shot purposes in rapid succession. I'm more than willing to let the system ask my app to die, but I'd like to keep warmed and ready otherwise.
View 4 Replies View RelatedHow to pause and resume the activity?
View 3 Replies View RelatedI have* two activities*,
*1st one* has a ques and 4 options.
*2nd one* is like a result page (... displaying if your ans is correct or not ...and showing the right ans ..)
Now what i want is when a user clicks :
on a right option [or wrong option] ..i want to turn that Image button into green [ red] .*.and wait for a while* ..and then go to the result activity ..
*so my only concern is onclick of a ImageButton ... how to wait for a while .. and then move to other activity* * * any kind of suggestion will do ..
I have one query. In Home Application the timer is running and if any ANR or Alert or Notify come then this home activity would go in Pause state but timer is running and visible. How it is happening. Can anybody explain me how this work.
View 4 Replies View RelatedI'm start a new Activity B from Activity A, and find launch Activiy B is very slow, cost over 3000 Milliseconds, and when i click "back" to Activity A, then i found this log below:
CODE:....................
Activity B only contains a ListView with CursorAdapter.
Any idea how does this happen? this performance is unacceptable.
Suppose i have a program that' s currently in a PAUSED state. Then the user launches another activity. In this second one, i want to find if the first one is in paused state or not because, if its paused, i want to recover it.
Is there a way to find if a specific activity is in pause state or not?
I created an application which is asynchronously communicating with the server. When the application makes a server request a new dialog (activity) with "loading" notification is created. The main activity implements methods for handling server responses and I would like to close the foreground activity when the main activity receives the answer from the server.
View 1 Replies View RelatedI'm trying to write a game engine in Android, but I don't have much familiarity with threads.
My thread has an attribute, mSurfaceHolder, which holds the surface that I'll be drawing to. The run() method for my thread looks like this:
CODE:.............
STATE_RUNNING represents the state when the activity is in the foreground and the game should be running.
STATE_PAUSED represents the state when another activity has come into the foreground. I'm not completely sure why I need to still draw while it's paused, but that's what I seem to have gathered from the LunarLander example.
What I'm hoping is that while I'm looking at the activity, the game will update and draw (which I test by using LogCat). And then when I go back to the home screen or another activity appears over the top, it will just draw.
Well it does draw and update while I'm watching the activity, so the game loop itself works. But when I leave the activity, it has no effect. Here is the thread's pause() method that is called from the activity's onPause():
CODE:.............
As you can see, to test this method I have logged some messages. Now what I find when I leave the activity is that "Here" is logged, but "There" is not. Now with my limited knowledge of threads (I hardly know what synchronized actually does), I believe this will happen because my thread can't get synchronized with the surface holder. But I don't know WHY it doesn't synchronize. A few seconds after I've left the activity, I see the following warning in LogCat:
Activity pause timeout for HistoryRecord
Any idea why this would happen? There are no problems if I try to start the activity again, the thread just keeps running as it was.
Just discovered something else. The thread pauses just fine if I leave the activity within about a second of having started it. And then it will resume and pause again with no problems at all while the same task is still running. I have no idea why for a short period of time it will work, but if I leave it too long, it won't.
Okay... I fixed it. But I don't think I'm supposed to do what I've done. I've basically removed any synchronization with mSurfaceHolder from both the pause() and the setState() methods (which is used by pause()). No it works as it's supposed to, but I'm thinking the synchronization is there for a reason.
Perhaps the best question for me to ask is this: WHEN should you synchronize a thread with an object by use of a synchronized block? And in this case, what is the purpose of synchronizing with the SurfaceHolder?
I am experimenting with using a WebView to display Flash content inside my activity. Everything is working pretty well, but when the user hits the home key to put the activity into the background, the Flash content keeps running (sound keeps playing, etc)
I have noticed that both the stock Android browser and Dolphin Browser seem to avoid this problem, and properly pause the Flash content when the browsing activity is put into the background.
Ideally I would like a solution that kills the WebView completely if the activity is finishing, but pauses it otherwise (basically copying the default behavior of the browser)
Here is a simple test I put together that loads a game on Kongregate which has some background music:
CODE:..............
I took a look at the latest source for the stock browser, and it seems to be doing something similar (calling pauseTimers/resumeTimers), although I fear the code I have been looking at is out of date, because it is calling functions that don't seem to exist anymore.
I did verify that the call to pauseTimers is working by testing with a simple JavaScript setInterval which updates a counter. Is there something else obvious that I should be trying in regard to Window or View management?
The documentation for the mobile Flash player says:
Flash Player will also automatically pause SWF playback it is not in view or the foreground application, for example when a call is received or alarm goes off, to reduce CPU utilization, battery usage and memory usage.
This seems to be working perfectly in both the stock browser and Dolphin Browser, but not in my app. Any ideas/solutions would be greatly appreciated!
Update: Here is the function we ended up adding to our activity to get this to work. We call it with "onPause" in the activity's onPause function and "onResume" in the activity's onResume function:
CODE:....................
Is this possible? I am trying to open a SQLite database cursor in one activity, and pass it to another activity.
View 2 Replies View RelatedonCreate, MyActivity will display five TextViews. After you touch one of the five TextViews, it will hide three to four TextViews and color one red and one green or just color one green.
I can code everything up to here. But how can I pause for a few seconds and then repopulate the five TextViews with new values, unhide them and make them all white?
I tried a Timer in a new project and can attach the code and make my question less vague.
Here is the main.xml
CODE:................
Here is the TestTimer.java
CODE:.....
The issue is that the Timer executes resetAndContinue and logs two entries, but it doesn't set the TextView color from green to white and it doesn't log anymore
CODE:.............
Ii have created a marker demowhich the marker on the map for which I have used pushpin.gif image. I have added the pushpin.gif in the drawable folders which is inside the resource folder. When I run it on the emulator the force close errror appears. I have also made sure that I add <uses-library android:name="com.google.android.maps"/> as a child of application which was given as an earlier solution by a friend on the discussion group. Still the error persists. I guess the code is fine.
package com.android.khushi.Googlemaps import java.util.List;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.MapView.LayoutParams;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Point;
import android.os.Bundle; import android.view.View;
import android.widget.LinearLayout;
public class MapsActivity extends MapActivity {
MapView mapView;
MapController mc;
GeoPoint p;
class MapOverlay extends com.google.android.maps.Overlay {
@Override
public boolean draw(Canvas canvas, MapView mapView,
boolean shadow, long when){
super.draw(canvas, mapView, shadow);
//---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
//---add the marker---
Bitmap bmp = BitmapFactory.decodeResource(
getResources(), R.drawable.pushpin);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
return true;
} }
/** Called when the activity is first created. */
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
} @Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mc.animateTo(p);
mc.setZoom(17);
//---Add a location marker---
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
mapView.invalidate();
} }
Last night all of a sudden my phone rebooted itself in my pocket. (not the first time) but after turning back on it throws this error at me com.sec.android.providers.downloads has stopped unexpectedly with a force close. Now every time I reboot it it comes up with the same error. Also it reset some of the factory settings (my internet browser got reset as well as my background and my alarms). Now everything is somewhat back to normal other then every reboot after I get that error my browser gets reset and I cannot download anything off there anymore (like pictures).
I have the Bell Vibrant not rooted or anything. 2.1 with a bunch of normal apps.
GT-i9000m
2.1-update1
Baseband i9000UGJG9
Kernal 2.6.29
Build ECLAIR.UGJG9
Is there any way to close the activity the launched another activity? So if activity A starts activity B can activity B close activity A? I know there is the tag android:finishOnTaskLaunch="true" but i only want it to happen if a button is pressed so im looking for a method to do it.
View 10 Replies View RelatedIn one activity I build a cursor which is used to populate a ListView. I want a secondary activity to be able to step through the cursor entries. What's the best way to do this (bearing in mind cursor lifecycle). I don't care if the the system kills and restarts the secondary activity since in that case the stepping through entries functionality could be temporarily automatically disabled.
View 14 Replies View RelatedI've got an android app that pulls a random 20 questions (rows) as a cursor from a SQLite DB and loops through all the questions to ask the user all 20 questions.
Is there some way to save the cursor's state/location when the activity is paused or stopped so that when the activity resumes the cursor is restored and in the same position as it was when the activity was paused/stopped?
When another activity is started from main activity, The main activity get destroyed and created when returned back from second Activity main activity remains in pause state till second activity finish (), on Sart or on Resume from when returned back from second activity? which one these case does happen in And roid application?
View 3 Replies View RelatedJust bought LG Optimus S which on sale (half price). The browser was working fine at the beginning. Root it and after that my browser kept force to close everytime i open it.
Unroot it back, and do factory reset, and now it is even worse, i cant even go to googleplay (market) or anything to do with internet, it kept showing me this error:
If open browser
The application Browser (process com.android.browser) has stopped unexpectedly. Please try again.
If open Market
The application Market (process com.android.vending) has stopped unexpectedly. Please try again.
As this phone is locked to my provider, i bought some unlock key to unlock, now my phone is unlock but this thing is coming.
I called LG, they offer me for services which will take more around 4 weeks
Lately, every time I startup or re-boot my phone, I get the following error message right after startup.
View 25 Replies View RelatedI keep getting this message, "The process com.htc.provider has stopped unexpectedly. Please try again." followed by a box to 'force close.'
I seem to remember it wanted to update about a week ago, so I hit ok and then the update failed. It has not asked to try and update again since then....
The phone will display this message upon start up and also will occur at other seemingly random times.
The phone works fine after pressing force close but does anyone know how to stop this annoyance?
I have three activity now, a, b and c, a is start point of activity lifecycle, and can go to b or c, and then assume go to b from a and close a, and then go to c from b but will not close b, and this time, I want to check whether b is start(create) or not,
if b start, I want to close b and then go to a, if b doesn't start(possible will go to c from a doesn't via b), it will also go to a but do nothing for b
how can I do for that?
I have a app,the structure composed three .java, 1.java,2.java,3.java
their relationship is: 1->2->3 and 3 can go back to 1
when i was back to 1 from 3, i want to close the 2, how to do this?
The structure of some of my activities is a simple ListView with a custom CursorAdapter. The cursor is created in onCreate() on the activity from a SQLite database. The problem is that querying the SQLite database can be quite slow at times with lots of data (and let's assume I've already optimized the sql query as much as possible). Because it occurs in onCreate() on the UI thread, I get ugly black screens when opening the activity, which sometimes turn into ANRs, on a slow phone like the G1. I want to load the cursor in a background and show "Loading.." on screen while doing so. I saw AsyncQueryHandler used extensively in the framework, but this seems a solution geared more towards Content Providers and not application-local SQLite databases. I then thought of trying to load the cursor in a background thread, but realize that this might be problematic, as the CursorAdapter should be instantiated in onCreate() and should take a cursor as a parameter. The latest thought I had was to instantiate an empty MatrixCursor in onCreate() and pass that to the cursor adapter, while kicking off a thread/TimerTask to query the database. Then, on database cursor load, call cursorAdapter.change Cursor to the properly filled cursor. This doesn't seem very elegant and seems quite wasteful, however.
View 10 Replies View RelatedI have an EditText field and I want to pop up a new window/activity whenever a user touches/clicks the field. The new window has some widgets and of course Apply and Cancel buttons. Here is the code how I intercept the onTouch event.
EditText ctlMaskEt = (EditText)findViewById(R.id.mask_field); ctlMaskEt.setOnTouchListener(new OnTouchListener() { public boolean onTouch (View v, MotionEvent event) { popMaskEditor(); return true; } });
Everythings work fine until I click the Apply and Cancel buttons. The API finish() won't close the new window unless I click the same button one more time. Calling popMaskEditor() from a button's OnClick event handler doesn't have this problem.
Is it possible to close/finish activities in activity stack from a backgorund service.
View 2 Replies View RelatedWhen I do various operations on bluetooth application ... scanning, renaming and discoverable after some time non of these works... if I try to change name, it is not reflecting. is it problem with Activity/service? How to check whether these are still running? How to debug such cases?
View 2 Replies View Related