Android :: Screen On/Off State?

Nov 3, 2009

I have an app that runs in the background indefinitely provided there is work to be done. I want the app to go to sleep if there is no work to be done and the user is idle. The second part has me stumped. On Windows Mobile I was able to poll the power state to determine user idleness. On BlackBerry I was able to poll the device idle time. However, there does not appear to be a way to determine user idleness on Android.

Instead of polling for user idleness directly, I thought I might be able to use the on/off state of the screen. There are 2 intents ACTION_SCREEN_OFF and ACTION_SCREEN_ON and I was able to setup a listener for these (BroadcastReceiver). The problem is that I do not know how to determine the current state of the screen at the time I register the listener, therefore I have to wait until the next screen on/off change to know anything. The docs speak of some intents that are "sticky" and thus will allow the current state to be determined, but the screen events do not appear to have that property. What am I to do?

In general, I find the lack of support for polling system state properties (e.g. screen state, power state, signal strength) in Android to be annoying. It's cool that one can listen for changes in system state rather than constantly polling for them, but one still needs to know the current state of the property at the time the listener is registered.

Android :: Screen On/Off state?


Android :: Changing Displayed State Of Views Based On Parent ViewGroup's State

Aug 11, 2010

I have a compound UI component built up from a ViewGroup containing a number of TextView, ImageView etc. components. Many of these have StateListDrawables as their images/backgrounds. Is there any way of making them select from this drawable based on the state of the parent ViewGroup rather than the component itself? Ideally I want to be able to change the visual state of all children of the ViewGroup (text colour, image etc) based on the state of the ViewGroup, preferably without having to hook up complex logical code. This seems like a fairly common sort of requirement, so I was hoping it would be straightforward in Android - am I going to be disappointed?

View 1 Replies View Related

Android :: Phone State Listener State Transitions

Feb 8, 2009

I'm a little confused by what I'm seeing with regards to phone state transitions via the PhoneStateListener. When I receive a call, this is what happens: (call comes in) RINGING -> IDLE (I pick up) OFFHOOK (I hang up) IDLE It's that first transition from RINGING to IDLE without any interaction from me (not ending the call, not answering the call) that confuses me. Do I really have to implement an idle counter to know that an incoming call has really ended? Seems like the reported phone state represents some sort of phone state that isn't the obvious one.Is this a bug or am I just not in tune with the paradigm here?

View 2 Replies View Related

Android :: Screen Freezing After 3 End Key Press In Unlocked State

Mar 7, 2010

After the animating logic implemented in powermanagerservice.java file this issue is observed.

Problem: In unlocked state(no call guard screen) press three time end key. Sceen is getting freezed i.e phone is not accepting any touch events.Screen is getting blurred and lines are getting shown.Keep the phone like that and whole screen goes for a toss.

However if you press end key again.Phone is getting back to normal state and starts taking touch events.

View 2 Replies View Related

Android :: CheckBox -- Restoring State After Screen Rotation

Mar 24, 2010

I have come across some very unexpected (and incredibly frustrating) functionality while trying to restore the state of a list of CheckBoxes after a screen rotation. I figured I first would try to give a textual explanation without the code, in case someone is able to determine a solution without all the gory details. If anyone needs more details I can post the code.

I have a scrolling list of complex Views that contain CheckBoxes. I have been unsuccessful in restoring the state of these check boxes after a screen rotation. I have implemented onSaveInstanceState and have successfully transfered the list of selected check boxes to the onCreate method. This is handled by passing a long[] of database ids to the Bundle.

In onCreate() I check the Bundle for the array of ids. If the array is there I use it to determine which check boxes to check when the list is being built. I have created a number of test methods and have confirmed that the check boxes are being set correctly, based on the id array. As a last check I am checking the states of all check boxes at the very end of onCreate(). Everything looks good... unless I rotate the screen.

When I rotate the screen, one of two things happens: 1) If any number of the check boxes are selected, except for the last one, all check boxes are off after a rotation. 2) If the last check box is checked before rotation, then all check boxes are checked after rotation.

Like I said, I check the state of the boxes at the very end of my onCreate(). The thing is, the state of the boxes at the end of onCreate is correct based on what I selected before the rotation. However, the state of the boxes on the screen does not reflect this.

In addition, I have implemented each check box's setOnCheckChangedListener() and I have confirmed that my check boxes' state's are being altered after my onCreate method returns.

Why would the state of my check boxes change after my onCreate method returns?

I have been trying to degub this for a couple days now. After I found that my check boxes were apparently changing somewhere outside my own code I figured it was time to ask around.

View 4 Replies View Related

Android :: Activity State On Pressing Back And Home Button On Screen

May 6, 2009

Whenever I press the home button when Im in the root task of my application and when I click on the icon of my app again the state of my task (activity) is retained, but when i press the back button on the emulator and when I open my application its state is not retained. I want the state to be retained in both the scenarios.

In the mnifest I have given the below entries,

android:alwaysRetainTaskState="true" for the root activity

android:launchMode="singleTask" for the application

View 2 Replies View Related

Android :: Prevent Custom Views From Losing State Across Screen Orientation Changes

Aug 22, 2010

I've successfully implemented onRetainNonConfigurationInstance() for my main activity to save and restore certain critical components across screen orientation changes.

But it seems, my custom views are being re-created from scratch when the orientation changes. This makes sense, although in my case it's inconvenient because the custom view in question is an X/Y plot and the plotted points are stored in the custom view.

Is there a crafty way to implement something similar to onRetainNonConfigurationInstance() for a custom view, or do I need to just implement methods in the custom view which allow me to get and set its "state"?

View 1 Replies View Related

Android :: ListView Checked State Wrongly Shared Between 2 Views When Reorienting Screen

Apr 25, 2009

I have TabActivity that uses 2 other ListActivities for the tabs. Both underlying ListViews are set to CHOICE_MODE_MULTIPLE. When I run the following sequence of events, I get a strange result: 1) Setup one activity (tab) and its ListView using a CursorAdapter, including checking some items on the list 2) Reorient the screen (open the keyboard) 3) Setup the second activity (tab) and its ListView using a CursorAdapter, including checking some items on the list 4) Switch back to the first tab

At this point, I can see in Eclipse that although (of course) each ListView is a distinct object, the internal variable used to store the checked state of items, called mCheckStates, is the SAME OBJECT REFERENCE in each of the ListViews.

Clearly this is an issue, since the two views should not share the checked state of items between them.

If I skip step #2, this does not occur

Here is a bit more detail:

After Step 1: ListView1 is object reference @1, ListView1.mCheckStates is object reference @2

After Step 2: ListView1 is object reference @3, ListView1.mCheckStates is object reference @4 (the reorientation recreates the views)

After Step 3: ListView2 is object reference @5, ListView1.mCheckStates is object reference @2 <-- note the reuse of this reference from step #1, not sure how/why

After Step 4: ListView1 is object reference @3 (unchanged), ListView1.mCheckStates is object reference @2 (changed) <-- same as ListView2.mCheckStates

View 8 Replies View Related

Android :: How To Read USB State?

Oct 27, 2009

Is it possible to know when the user unplugs a charger or headsets from the device so I can trigger something..

View 2 Replies View Related

Android :: How To Get Service State?

Jan 6, 2010

I'm trying to get current service state of my phone. It can be easily fetched with get State() method of Service State when a on Service State Changed (Service State service State) callback is invoked: Code...

View 2 Replies View Related

Android :: Dev - Save State

Sep 1, 2010

can someone helpme out with how to save state of the app when the screen orientation is changed i read the development guide at http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange

But i dont know how to define the method collectMyLoadedData();

View 2 Replies View Related

Android :: Restore Instance State

Aug 24, 2010

I need to save some state when the user leaves my game during game play. Saving the state doesn't seem to be an issue, but I can't figure out how to restore it. The onCreate function isn't called when the Activity is resumed (only when it is first created), so I can't get my state back there. Logically, I would use onRestoreInstanceState, but it isn't being called.

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

I see log output from onSaveInstanceState, onResume, onCreate, etc, but I never see a log message from onRestoreInstanceState and savedState is always null. Why isn't onRestoreInstanceState being called, and is there another way to get my state back?

View 1 Replies View Related

Android :: Usability / State Vs Verb?

Feb 26, 2010

My business partner and I have a small disagreement, and I'm trying to figure out the best way to resolve it. First, I should say I started out his way, and switched after reviewing a lot of applications. The background is this -- we have an app, with some controls which can be locked. A lock/unlock icon is put next to the lockable controls. You can long-click the icon, and it brings up a context menu with several items, including the item for the lock state.Currently, it brings up a "Locked [X]" or "Locked [ ]" item -- that is, a menu item with a checkbox that can be checked or unchecked, and the lock state is changed accordingly.He would like me to change it to reflect the action being taken. I.e. the menu item would say "Lock" if it is currently unlocked, and "Unlock" if it is currently locked.It would be acting as a toggle in either case; the only difference is how it is presented to the user.

View 7 Replies View Related

Android :: How To Get BT State / Update Application?

Apr 24, 2009

At the moment I am trying to update my application to Android 1.5. In Android 1.1 I was able to detect the BT state with catching the following broadcasts: Code...

View 8 Replies View Related

Android :: How To Save App State In Phone?

Aug 30, 2010

I am writing an app where I get all the data from the rest call and display all the data in a custom component list(based on Linear Layout) which is added to a LinearLayout. I write this code in onCreate of the activity. The problem is when I switch activity using startActivity, and come back to the calling activity (using startActivity) then onCreate is called again. I see onPause, onStop called when I call other activity. Is there any way that I can save the application's state?

View 1 Replies View Related

Android :: How To Get Pressed State Of Preference

Sep 10, 2009

There is know problem in all the Android phones. Go to Bluetooth Settings->Turn ON bluetooth->Click on bluetooth discovery->Then timer will start in summary->Long press on Bluetooth device discovery-> observe Bluetooth ON/OFF title start to toggle with Bluetooth Discovery toggle. I analyzed the issue. Blueooth ON/OFF is CheckBoxPreference. Bluetooth Discovery is also CheckBoxPreference which has dependency on Bluetooth ON/OFF. When we click on Bluetooth discovery then On thread will run at every second to update summary in Bluetooth Discovery preference. When we change the Bluetooth discovery to OFF then thread will be removed/ killed. When i press the Bluetooth discovery for long time when its already in ON State then still the thread will be updating the summary (remaining time from 120 to 00) till i press it. When i leave the Thread will stop. As it has dependency on Bluetooth ON/OFF, its making to the title invisible. But it should not happen. Solution: When i touch the Device Discovery i should kill the update summary thread then i guess, that problem will be solved. But in prefence i dont have any listener to know the pressed state. I hope somebody can give me solution.

View 2 Replies View Related

Android :: Saving Application State?

Jan 11, 2010

I understand how to save an application's state by using SharedPreferences, onSavedInstanceState() & onRestoreInstanceState(), etc as outlined in a similar post ( http://stackoverflow.com/questions/151777/how-do-i-save-an-android-applications-state ), but how do I save the last activity?

To be more specific, my application starts up and goes to a login screen. Once a user logs in and navigates through several activities, lets say he or she leaves the app using the home button or in some other way. Next time the user starts the app, it will go back to the login screen and do a login again. Instead, I want the app to start up and go to the last activity that was on top of the stack when the user left the app in the previous session.

How is the last activity saved so that it can be restored on app startup?

View 3 Replies View Related

Android :: Get Current Sensor State?

Feb 7, 2010

Yes, I can get sensor update events with SensorEventListener. But this approach has 2 drwwbacks:

1) For some sensors I have to wait for the state to update. For example, temperature may update after a minute!

2) In some cases I can get incorrect readings. For example, the phone lies on a flat surface and does not move. I receive first orientation update event after listener registration. When only a part of the orientation vector changes, other parts may be 0. And it is no way to determine, is it a true 0 degree azimuth or just an incomplete vector. If I move the phone a little, the correct non-zero azimuth appears.

To solve this problems it's possible to create a separate thread that constantly monitors sensors. After some time it will certainly contain true values. But I think that it is an overhead for such simple task.

Is it any other way to get current sensor data?

View 1 Replies View Related

Android :: ImageButton With A Selected State?

Apr 9, 2010

If I was using an ImageButton with a selector for its background, is there a state I can change which will make it change its appearance? Right now I can get it to change images when pressed, but there seems to be no "highlighted" or "selected" or similar state which lets me toggle it's appearance at will.

Here's my XML, it only changes appearance when pressed.

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

View 2 Replies View Related

Android :: Saving State Of An Application?

Jul 5, 2010

Which of the following is/are appropriate for saving the state of an Android application?

a. Activity.onFreeze()
b. Activity.onPause()
c. Activity.onStop()
d. Activity.onDestroy()
e. Activity.onFinish()

View 2 Replies View Related

Android :: Saving And Restoring State?

Jul 15, 2010

I have searched through this and a few other sites for the answer, but I have been unable to find it. I am trying to save a boolean and an int using onSaveInstanceState and onRestoreInstanceState, but I can't seem to get it to work. It doesn't crash or anything, but it either isn't saving it or it isn't restoring it, or I am stupid and have no idea what I am doing.

Here is what I have for my activity, do I need to have it in my onCreate somewhere or something?

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

I tried putting stuff in the onStop, but it crashes, which is why its empty, in case that matters, thanks in advance

View 2 Replies View Related

Android :: Save State In My Application

Jul 16, 2010

I am developing an android application in which,the first activity is that for Login. After successful authentication, user can see an activity with 4 Tabs. My problem is that when user taps on the home button,the application should terminate and when the user again starts my application, he should be able to see the Login screen again and after successful Login, user should be able to see the tab on which he was working before application terminated(i.e., save state for all the tabs).

View 3 Replies View Related

Android :: Save .app.Application State?

Aug 9, 2010

I've encountered a problem wile using my own subclass of android.app.Application. I have numerous activities in my application and I'm running a custom ROM which consumes quite a lot of memory. What happens is when I launch a third party activity (Camera) my Application is killed. My Application subclass stores vital data for the whole app so it can't work without it. android.app.Application doesn't have any methods for saving or restoring application state. Activity does have them but they are not suitable.

How to perform save/restore state on Application subclass?

UPDATE I've managed to do so by filling a Bundle obtained from onSaveInstanceState and restoring values in onCreate. But is there any better way?

View 1 Replies View Related

Android :: How To Know Whether A MediaRecorder Is In Running State Or Not

Aug 11, 2010

I wrote a code to record audio of call conversation using MediaRecorder.

how can i know whether a MediaRecorder is in running state or not, to stop the recording.
like

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

Above code is just an example.. If you do not understand my question, please tell me.. i will explain clearly with actual code..

What all i want to know is "In which state the MediaRecorder is?" -> recording/released/prepared/initial/etc..

View 1 Replies View Related

Android :: Get Key Events In Keylock State?

Aug 13, 2009

Basically I have handle the volume UP/DOWN key events when device in key lock state. How I can do this?

View 2 Replies View Related

Android :: Save State Between Orientations?

Sep 4, 2010

In a previous question I asked how I could display two different layouts for portrait and landscape orientations:

Problem switching to landscape orientation

Now I would like to know how I can save the state of my application before it goes into another orientation? I seem to lose this data any time orientation changes.

View 1 Replies View Related

Android :: Can't Set Checkbox State In OnPrepareDialog

Nov 6, 2010

I've got a dialog which shows a list of checkboxes. The info which boxes should be checked each time it opens comes from an edittext. I searched for a way to not allow caching of the dialog but couldn't find out how to do that. Now I override onPrepareDialog to set the checkboxes before the dialog opens. I deleted the content of my edittext, opened the dialog and there were still the same boxes checked... how to reset the checkboxes?

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

View 1 Replies View Related

Android :: No Broadcast On SIM State Change / Get It?

Jul 11, 2009

Am I right if I say that, there is no broadcast action currently for the SIM card state changes?

View 2 Replies View Related

Android :: Get SIM State In GsmServiceStateTracker.java?

Aug 10, 2010

How can I get to know whether SIM is present or not in GsmServiceStateTracker.java file?

View 1 Replies View Related

Android :: ToggleButton Won't Keep State In ListView / Why Is So?

Oct 5, 2010

Any one knows why my ToggleButtons won't keep their states in a ListView?

Each list item includes a ToggleButton - when scrolled off from the screen their states are reset to unchecked...

I presume getView() is called once they're visible; however I'm not re instantiating them anyways.

View 2 Replies View Related







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