Android :: Check Value Of ListPreference In OnResume()?

Oct 12, 2010

I have a ListPreference with the entries and entryValues correctly set. When I go in the prefernces activity and change the value it successfully works (I added a Toast to output the value after changing the option to test). But when I do the following to compare it, it always executes the else statment when I change it everytime, even like above when I changed the ListPreference and the value was "bluesky" it still failed to execute the correct if statement. Here's the code I use to check the value of the ListPreference in the onResume():

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this)
String backgroundPref = prefs.getString("backgroundPref", "");

if(backgroundPref == "bluesky"){
mainLayout.setBackgroundResource(R.drawable.bluesky);
Toast.makeText(getBaseContext(), "Blue Sky", Toast.LENGTH_SHORT).show();
}else if(backgroundPref == "sky"){
mainLayout.setBackgroundResource(R.drawable.sky);
Toast.makeText(getBaseContext(), "Sky", Toast.LENGTH_SHORT).show();
}else{
mainLayout.setBackgroundResource(R.drawable.sunsetscene);
Toast.makeText(getBaseContext(), "Sunset Scene", Toast.LENGTH_SHORT).show();
}

The Toasts are there so I can double check which statement gets executed, and it always seems to be the else one. Am I having a bad day and getting something wrong?

Android :: check value of ListPreference in onResume()?


Android :: Implementing Multi Select (check Boxes) ListPreference

Aug 29, 2010

on implementing a multi-select (check boxes) ListPreference on Android? Would I have to extend the ListPreference? Is there any classes already documented to do this?

View 1 Replies View Related

Android :: Android Market Licensing Check During OnCreate Or OnResume?

Aug 21, 2010

In the included LVL sample app, the license check is triggered during onCreate. This means that when I click "Buy App" to launch the market, then immediately hit the back button to return to the app, the dialog is gone and another check isn't performed, leaving me with a perfectly usable app (at least until the activity is killed and the process starts over again).Would triggering the license check during onResume() be bad form, even though it would fix this issue? Is there a better solution?

View 2 Replies View Related

Android :: Calling Finish() In OnResume()?

Sep 8, 2010

I've been using code like: activity.finish(); activity.startActivity(new Intent(activity, activity.getClass()));

in two places: onResume(), and in an onClick() method of an AlertDialog. I'm getting the desired results when the code is called from onClick(), but I get mysterious null pointer exceptions while the runtime is trying to execute my onPause(). Is calling finish() from within one of the Activity lifecycle callbacks always a bad idea?

This code makes me nervous even though it works in the onClick(). After I call activity.finish(), I would think activity is in a questionable state by the time activity.startActivity() is invoked. Seems like an invitation to race conditions.

My use case is setting UI preferences (e.g. a different layout) in a PreferenceActivity. When I return to the main activity's onResume(), I check for preference changes and if a new layout is requested, I use the code snippet above.

View 10 Replies View Related

Android :: AnimationDrawable : Can't Be Started In OnResume / Why Is So?

Jan 27, 2009

There's already been some discussion of this, in various lists and blogs. I finally got an AnimationDrawable to work, but I cannot start it from onResume. I can start it from a timer that onResume starts, or an onClickHandler.

I've poked around the source a bit and I can't figure out, specifically, what state the view has to be in, in order for the background AnimationDrawable to start.

Can anyone enlighten me?

View 5 Replies View Related

Android :: Something Like An App Global OnPause() And OnResume()?

Jan 14, 2010

Is there something like an application global onPause() and onResume()?

My main activity listens for GPS fixes, which I want to continue working when switching to another screen/activity. Therefor I cannot unregister my LocationListener in the activity's onPause(). However I still want to unregister my GPS listener when switching to another application (so save battery) and turning it back on when returning to my application, regardless what screen/activity the user is currently in. Any ideas?

View 1 Replies View Related

Android :: Interactivity Coordination OnStop And OnResume

Oct 16, 2010

I have two activities. One loads all rows from a database, and the other saves to the database. When I have the second save in onStop and the first repull the data in onResume, they do it out of order (the first resumes and then the second saves). I managed to fix this by putting the saving data in onPause, but why was this happening? Was this the cleanest way to do it?

View 1 Replies View Related

Android :: OnResume Is Always Called On TabActivity So OnCreate Is Not Necessary?

Sep 15, 2010

I have a TabActivity with 3 tabs, each tab started an activity and I realise when a tab is clicked onResume is call. If I have onCreate, when app start it will launch onCreate and then onResume immediately.So, I can just get ride of onCreate in this case?

View 2 Replies View Related

Android :: Open A Dialog Immediately After OnResume?

Sep 18, 2009

I need to open a progress dialog on the onResume() method. But no dialog is opened. Any solutions for this?

View 3 Replies View Related

Android :: Binding To Service In OnCreate() Or In OnResume()

Feb 20, 2010

I want to know what es the best place in an Activity to bind to a service? I saw examples doing it in onResume() and also in onCreate(). I was asking myself if it is not a problem putting it into onCreate(), cause in onPause() i will do a unbind to the service, so i dont get a serviceConnectionLeak, if i leave the activity. Now if i press the Home-Button and then switching to the HomeScreen, the Activity will unbind from the service, when i go back to the Activity from the Taskmanager, then onCreate() will not be called and if the Code is trying to access a function from the service i will get a null-pointer exception. If i bind and unbind only in onResume() and onPause() i dont have this problem.

View 3 Replies View Related

Android : OnResume Called While Device Is Off For Hours

Mar 19, 2009

I have documented cases of an activity's onResume method getting called HOURS after the G1 is - well, not asleep, since a WakeLock is in use, but "idle" with the screen off (indeed, it had been off in one case for 6+ hours).

View 2 Replies View Related

Android :: OnPause / OnResume Activity Trouble

Mar 14, 2010

I have a small test application I am working on which has a timer that updates a textview to countdown from 100 to 0. That works fine, but now I am trying to pause the application if the user presses the back button on the phone and then restart the timer from where they left off when they reopen the app.

From the Log.v() prints I see that the _timer_time_remaining variable has the correct number of seconds stored when onPause is called, but it is set back to 0 when onResume starts. Why does the variable get reset? I thought that the application would continue to run in the background with the same values. Am I missing something? This is all declared in a class that extends Activity.

View 2 Replies View Related

Android :: Setting Spinners OnResume Doesn't Work

May 8, 2010

I want to save text from 2 edittexts(et1,et2) and selection from 3 spinners(spinnerm,spinner and spinner2) onPause and setting them back onResume.

Text from edittexts is saved correctly, only spinner selection don't work as desired.

My code:....................

View 1 Replies View Related

Android :: Way To Carry Data Over Between OnPause & OnResume / Used SharedPreferences

May 30, 2010

I'm having a hard time figuring out the best way to pass simple values from onPause and onResume in the Android activity lifecycle. I understand how to use get and put extra bundles for activity to activity data, but does that work for passing data between the same activity? Should i used SharedPreferences?

View 1 Replies View Related

Android :: Getting Key From ListPreference

Oct 2, 2009

When using a PreferenceActivity to do preferences, the PreferenceScreen can contain a ListPreference. A ListPreference has an array of keys and an array of values. But the PreferenceActivity only writes the values to SharedPreferences. How do I get the key of the item selected from the list? I would have thought this is pretty fundamental, especially if you want to translate your app.

View 13 Replies View Related

Android :: TextView With URL Throwing Exception When Finish() Called In OnResume()

Apr 6, 2010

I created a TextView and put an url to it, using setText(Html.fromHtml("");. Its opening the web page in the built-in browser and when I press back, its coming back to the application.

I don't want to come back to the application, so in activity's onResume(), I call finish(). Its exiting at the first time. But when I open the application again, its throwing some exception.

Any other way to close the application, other than this way.

View 2 Replies View Related

Android :: No Ok Button When Using Listpreference

Mar 25, 2010

I'm using listpreference in my android app and getting my key values and all is well and works good (now that you guys have helped me) BUT - when my listpreference menus popup, they only contain a cancel button. Let's say the user is choosing between red, blue, and green. When the listpreference dialog first pops-up, the dialog only shows a cancel button. Because of that, the dialog disappears as soon as the user selects their choice. I would like it so that when the user chooses their setting, they see the radio button get highlighted and then they go ahead and click the ok button...but I don't have an ok button and can't figure out why.

View 1 Replies View Related

Android :: Customize Row In ListPreference

Aug 7, 2010

Is there a way to use a custom row for the ListPreference in the Android preference screen? Currently I populate the ListPreference like this, but I need more info (description) shown in the List

int count = items.size();
CharSequence[] entries = new CharSequence[count];
CharSequence[] entryValues = new CharSequence[count];

for (int i = 0; i < count; i++) {
entries[i] = items.get(i).toString();
entryValues[i] = String.valueOf(i);
}
langPref.setEntries(entries);
langPref.setEntryValues(entryValues);

View 1 Replies View Related

Android :: Dynamic Content Of ListPreference

May 28, 2010

I want to put a ListPreference in my preference screen. But all the examples I have found in Internet the content are loaded out of a xml and I need that de options in the ListPreference are dynamic and not previously defined (in a xml).

I have mi preferences.xml in the folder xml/ of my project;
this is the code of preferences.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android

View 4 Replies View Related

Android :: Display Current Value Of XML ListPreference

Mar 6, 2010

I have an XML preferences screen which is handled by addPreferencesFromResource. On it, there is a ListPreference, for which I want the summary to contain the current value of that preference. I think this would be a common requirement, as otherwise you could not see the present value of the preference without expending a click. I read that the summary field supports resource references, and I see that I can refer to preferences as android:summary="@+preference/prefname" in my ListPreference. Clearly this is why resource references would be supported in this field. However, when I try this, instead of the present value of prefname, the text "false" appears as the summary. Does anybody know how to display a current value without taking the seemingly ridiculous step of rewriting the entire (large) preference screen in Java?

View 5 Replies View Related

Android :: Set Default Value To ListPreference Item

Sep 22, 2010

I'm trying to set a defaultValue to a ListPreference item. Here is an sample of my preference.xml file:

<ListPreference android:key="notification_delai"
android:title="@string/settings_push_delai"
android:entries="@array/settings_push_delai_human_value"
android:entryValues="@array/settings_push_delai_phone_value"
android:defaultValue="????">
</ListPreference>


The two arrays:
<string-array name="settings_push_delai_human_value">
<item>every 5 minutes</item>
<item>every 10 minutes</item>
<item>every 15 minutes</item>
</string-array>.............

View 1 Replies View Related

Android :: ListPreference In Preference View

Jan 17, 2010

This is my first Android app (which is a soft keyboard, with dvorak layout) and so far it has gone pretty smoothly (either because or despite working from the sample code). I've had some problems (with special/swedish characters) that I've managed to take care of, but this problem I can't figure out how to solve..

But when I click the list item to edit it, i get an empty dialog (Title and button is shown right and with the text I set in the xml- file, but no list, screenshot: http://i49.tinypic.com/2501p55.png ). I can't see any problem with the program code (which isn't many lines..) or the xml (the arrays are generated by the Android utils in Eclipse and the preferences is a mix of auto and manual). You can see both Java code and XML here: http://pastebin.com/m4c52c3a2 (titles etc in Swedish..) (I've also tried a EditTextPreference item, which seemed to work fine..) I have also looked at the log/output using adb, and can't see any problems there either, so I have no idea onto how to solve this.

View 2 Replies View Related

Android :: ListPreference NOT Save To SharedPreference?

Mar 21, 2010

I am resuing ListPreference for a setting which I store in the database. I do not want it stored in the preference file. How can I reuse ListPreference in such way that it does NOT save to SharedPreference file?

View 2 Replies View Related

Android :: Using Listpreference And Retrieving Key String

Mar 23, 2010

I have a settings menu that pops up and in it is a listpreference type menu. It is associated with a settings.xml file where there are 'array-strings' within it. It all works good but I don't know how to retrieve the users preference. As an example, let's say the user picks a color (red, green, or blue). The list that I've made within my 'array-strings' contain the text red, green, and blue. Within my code, I would like to do something if the user has choosen red, something else if they choose blue, etc., etc. Would I use a 'case' statement or an 'if' statement? And most importantly, how would I retrieve the users preference - the key? (am I checking for a boolean?)

View 2 Replies View Related

Android :: Simple ListPreference Is Not Working?

Aug 27, 2010

I'm betting im missing one small thing. I've looked on the developer site and i've read some tutorials and i'm just not seeing what i did wrong. I'm trying to use a ListPreference to decide which sound to play on a button click. I have this at the top:

public String greensound;
Here's my OnClick code:
case R.id.green:
SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
greensound = prefs.getString("greensound", "gsone");
if (greensound == "gsone") {
mSoundManager.playSound(1);
} else if (greensound == "gstwo") {...................

View 3 Replies View Related

Android :: ListPreference To Play Sound Is Not Working

Aug 28, 2010

I'm trying to use a ListPreference to decide which sound to play on a button click.

I have this at the top:

public String greensound;

Here's my OnClick code:................

I also tried removing the default value here it didnt seem to change anything but, should it be removed?

Here's my Settings.java:

package com.my.app;

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

And here's my array's if that will help at all:

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

Here's a logcat that kinda looked possibly related:

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

For those that might ask here's my DDMS > File Explorer > Data > Data > packageName > SharedPreferences This is what was in there:

com.my.app_preferences.xml:

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

This all really confuses me more because...It looks like greensound does == gsone so.... I don't understand whats wrong its not even playing the default sound. and yes i've tested all this code without the listpreference code and they work great. I'm not sure what's wrong?

View 1 Replies View Related

Android :: Create Multi Choice In ListPreference?

May 30, 2009

ListPreference default is Single-Choice, how to create Multi-Choice?

View 3 Replies View Related

Android :: ListPreference With Max Number Of Selectable Options

Jan 6, 2010

I want to have an element in my preference menu that does the following: Show a list of options. Many are selectable Maximum amount of options to be chosen 2. Possibilities I thought of: Doing a separated PreferenceScreen and showing options as checkBoxes but I don't know where to place the logic of max 2 options. Extending DialogPreference and doing it by hand.

View 2 Replies View Related

Android :: Use ListPreference Modal View In ListActivity?

Mar 2, 2010

I am trying to put together a modal box with a scrollable list of checkable items and an OK and Cancel button at the bottom for the user to select filters from. It seems the simplest way to do things like this in Android is to reuse API components (widgets, layouts, etc) and the closest one I can find to this looks to be the ListPreference, which basically does exactly what I want (I can even work with storing the data in SharedPreferences). The problem is that I'm not launching this modal box from a PreferenceActivity, but rather will be launching it from either of two activities: a ListActivity and a MapActivity.

View 1 Replies View Related

Android :: Account Preferences Crashes On ListPreference

May 14, 2010

I have created an account type using the AccountAuthenticator stuff as done in the SampleSyncAdapter tutorial. I am now trying to get account preferences working. I have added the line android:accountPreferences="@xml/account_preferences" to my account-authenticator and account_preferences.xml looks like so:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/alum_settings_title"/>
<CheckBoxPreference
android:key="sync_alum"
android:title="@string/sync_alum"
android:summaryOn="@string/sync_alum_check"
android:summaryOff="@string/sync_alum_nocheck"/>..................

View 5 Replies View Related







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