SeekBarPreferences are changing but not visually - android

I've been trying to work this out for 2 days now and I have absolutely no idea how to fix it.
Essentially, I have a service that listens for changes in a ListView (via a BroadcastReceiver) and updates several SeekBarPreferences accordingly via editor.putInt("SeekBarPreference", value).commit();. Now everything works as it should and it returns the correct values BUT it wont change the seekbarpreferences visually. If I restart the service (press back and then click on the relevant option) they change to the correct positions. Or even if I rotate the device they change.
I guess my question is; Is there any way to manually "refresh" the 'look' of the preferences?
Thanks!
(I know there are similar questions on here, but none of them really have a solution)

A lame way I sometimes fall back on is to relaunch the activity. Create an intent for the current activity and launch it. Two lines of code. Don't know if its a practical solution for your problem, but its worked in various situations for me.

did you try invalidate() or requestlayout() on that view?

Managed to get the seekbars updating on the ponSharedPreferenceChanged listener by clearing the preferences
PreferenceScreen prefScreen = getPreferenceScreen();
prefScreen.removeAll();
loading the xml again
addPreferencesFromResource(...etc.
Then re-sending the broadcast to update everything
It works, but it isn't very elegant. Thanks to everyone for helping!

Related

Screen rotation breaks widget Android

When I rotate the screen on a tablet, my widget's list view disappears and the buttons become unclickable. I'm not sure what happening with the most recent remote view to cause this. Any suggestions?
Here is my onUpdate function
onUpdate
Since we do not have the full code, it's kind of hard to give an actual answer to your problem.
However, I might have an idea & the cause of your problem could be in your .XML file. The same way your app looks great in a certain rotation, most surely on the one you originally designed your work on, it is very possible that it might result in problems when you changed the rotation.
However, it all depends of the layouts you are using & how they are used. I would advise to share your entire code so we can go through it.

Update a layout after an orientation change in a Fragment

Good day,
I'm working on an application that will serve as a monitor of some sort for drivers. My client would like the application to work regardless of the orientation of the device.
I implemented the solution provided in the following article , and after fiddling a bit with the debugger, I can see that the Asynctask is still working. However, the TextViews and ImageViews it is supposed to work on are not working anymore.
Here is the code of my TaskFragment.
To clarify : The AsyncTask still receive and handle the elements correctly, but the elements of the layout are not updated anymore. I would like to know how I can keep them working.
I would suggest using an AsyncTaskLoader as those can re-attach to whatever lifecycle element you created it in relatively easily. See here: https://developer.android.com/reference/android/content/AsyncTaskLoader.html
It might seem pretty involved to implement at first, however if you read https://developer.android.com/guide/components/loaders.html, most of the weirdness should be cleared up.
TLDR: Using AsyncTaskLoader allows an easy way for your AsyncTask to be reattached to your fragment after it is destroyed and recreated. You just need to call getLoaderManager().initLoader(...) in the onCreate of your fragment.
Ok, so I found a (probably not very efficient) workaround, but a workaround nonetheless.
The problem was that, after an orientation change, since the Activity is destroyed and recreated, the variables batterymonitor, valuemonitor, etc, would not point towards the new objects created because of the layout/activity change.
As a solution, I am now using a findViewById each time I need to do an operation on the layout. This way, the id is permanently refreshed to keep up with the activity changes on a rotation of the device.
The ugly line I use to do so is :
batteryMonitor = (ImageView)getActivity().findViewById(R.id.batteryMonitor);
batteryMonitor.setImageResource(R.drawable.no_battery);

ImageView not updated after device is switched off an on again, while app is on top

My MainActivity essentially shows two ImageViews. In order to make sure that the Bitmaps in the ImageViews are shown under all circumstances I do the following in the onResume method of MainActivity: load the Bitmaps bmp from preferences and assign them with
iView.setImageBitmap(bmp).
This works well after returning from another activity or when the user switches to another app and comes back to my app. But it does NOT work, when my app is on top of the screen, when the user switches off the device and turns it on again later. That is rather strange, since I explicitely load the Bitmaps from preferences and assign them again in onResume. This is also true for the latest devices e.g. the S7. Any advice highly appreciated!
you should check first if onResume() is called via
Log.d(..)
sorry i cant comment (50 rep)
Switching the device off and on would assume onStart and not onResume.
If you haven't done so do, whatever you did onResume onStart.
:)
It turned out that I had to do the assignment of the Bitmap via
iView.setImageBitmap(bmp)
already in the onCreate method. I assume that some layout inflation tasks are performed more thoroughly within onCreate than anywhere else. At least in the case of the turn off/on story this seems to be true.

Android ICS widgets - listviews goes blank randomly (when launcher restarts?) RemoteviesService bug?

I've widget with listview inside and few times per day the listview items just disappears. I find out that it can be due to launcher restart - so I tried a little test. I manually restarted launcher, and it just confirmed my suspicion - it's definitely because of launcher restart.
How to deal with this? The rest of widget (buttons, listeners, ...) are working, just listview items disappear and I can't even see empty_list layout, that I defined - that's why i must add to my widget manual refresh button, but it's not very good solution...
The problem you are encounterung seems to be a known issue: see link here: http://code.google.com/p/android/issues/detail?id=28216
There you can find some workaround on how to fix this.
ok except that it's ICS bug, it's partially also my fault - just always recreate widget content in onUpdate method and it will be ok ;)

Widget Preferences "delay" problem

I have a Widget with his android.appwidget.action.APPWIDGET_CONFIGURE Activity with some preferences witch I can set before adding it to the "desktop".
My problem is that the preferences does not get applied because I noticed that as soon as the APPWIDGET_CONFIGURE is called, the widget is created and never refresh after the widget is actually applied to the screen and it actually never reads the updated preferences.
Any thoughts?
Thanks
Oh, I think I found what it seems to be an easy solution but I don't like it much so I like to have a "second opinion". I don't say what it is to not influence the answers.
PS. The configuration activity works fine, the problem is only when the widget is applied for the first time.
The (easy) solution I found is to call an update on the widget after closing the APPWIDGET_CONFIGURE Activity.
The "dirty" thing I don't like is that you actually "draw" the widget one extra time.

Categories

Resources