How to create multiple instances of the same widget with different data? - android

I have this widget with a RemoteViewsService.RemoteViewsFactory adapter to populate a ListView.
How would you retrive different data for each widget instance if the RemoteViewsFactory is always the same (unless it got killed)? The data is choosen by the user with a Configure activity on widget creation by the way.
Thanks to anyone who can provide even the smallest input.

Related

How to pass new data to onCreateLoader

I have an Activity that implements LoaderManager.LoaderCallbacks<Cursor>. The CursorLoader feeds into a RecyclerView (think ListView). So inside onLoadFinished I swap the data inside my adapter.
Imagine the data has to do with stock performance for a day. Now I have a Spinner that allows the user to choose a day. And when the user changes day I want the data to change. So I am thinking that the Loader needs to be able to listen to the parameter. How do I do that? Per the documentation of getSupportLoaderManager().initLoader I am not sure if calling it inside my spinner’s onItemSelected will do that trick. Thanks for any help.
And when the user changes day I want the data to change. So I am
thinking that the Loader needs to be able to listen to the parameter
to me, it sounds like you want to requery your database again when those data change. you can use restartLoader. You have to possibility to provide a different id, which can be used as identifiers for the specific loader. From the documentaion:
Starts a new or restarts an existing Loader in this manager, registers
the callbacks to it, and (if the activity/fragment is currently
started) starts loading it.

Share CursorAdapter instance between Activities

I have an activity that loads result from the database using ContentProvider and LoaderManager.LoaderCallbacks interface and displays in a list. It works fine no major problems so far.
Now I want to display detailed view in another activity after clicking on the list item, I was thinking that if I already fetched the data I could share the CursorAdapter instance and this way have it reused and make possible to change content from within the DetailedView by flick gesture.
Q: Is it possible without leaking memory in the application?
Q: If not then how to accomplish this?

Where to get Outside Data from RemoteViewsService.RemoteViewsFactory

I need to populate a ListView in a Homescreen Widget. I know I use RemoteViewsService.RemoteViewsFactory as a sort of Adapter.
I also know how to populate the rows in getViewAt() method to show this.
However, I need to populate an ArrayList of Objects from the Network and pass that into the getViewAt() I am not sure where or how to go about doing this?
In a normal adapter, I simply pass this in the constructor. Would it be the same here?

Sharing data between services and activities

I have a ListView with a custom ArrayAdapter, that shows orders from an ArrayList. These orders are supposed to be synced with my server. There I have an API, which I am requesting for new orders, and if there are any, I get an XML of the order back. What is the best approach to dynamically update the listView? I do not want to use SQLite to store the orders, because only last ten are supposed to be displayed. With a ContentProvider I am not able to store my custom Order object. And if I wrap the ArrayList into a singleton class and use it in the service as well as in the Activity class for the ArrayAdapter, the ListView is not dynamically updated (probably, because the arrayAdapter makes a copy of the arraylist?). Thank you very much.
Filip
use Intent or Bundle
i'm no sure what you mean regarding the ArrayAdapter not being updated, but i can give you a solution we used in my company.
I have a DataMaanger which is a bridge between the Activities and the Networking or SQLite.
The dataMaanger keeps it's data in memory so it's not in DB or on disk. the disadvantage of it is if your app gets killed for lack of memory and reconstructs itself, the dataManager will be empty, which leaves you with two options, either on every Activitie's death or you main task's activities death you serialize your DataManager's data, or if you are not dependant on any previous data, just make arequest again and update the data manager.
I use broadcasts to notify my activities.
To get an access to the DataManager i don't use a sigletone. i use the Application object, you can extend it and in the Manifest.xml give it's name in the tag, then it will be used instead of the regualr Application object.
You can access it later by using getApplication() method in Activity class.

Stack widget delete & add views dynamicly Android 3.0

Can anyone give me an example of using a Stack Widget and being able to remove and add views dynamically.
Here is an example.
1) Widget loads and you add 4 views to the widget
2) User loads and activity within the same widget package and uses a button to delete one of the 4 views.
I need an example how to do that.
Thanks for the help!!
Your StackView widget should have an implemntation of the RemoteViewsService.RemoteViewsFactory interface which includes the onDataSetChanged() method. Within this method you need to update the widget from your data source.
Then in your application, any time your data set changes you can then tell any instances of your widget to refresh themselves by calling:
AppWidgetManager awm =
AppWidgetManager.getInstance(getActivity());
awm.notifyAppWidgetViewDataChanged(awm.getAppWidgetIds(new
ComponentName(getActivity(),
Your_App_Widget_Provider.class)),
R.id.your_stack_view);

Categories

Resources