That isn't clear. Do you mean that each item added to the List includes a Switch?
Last week, you wrote:Each list item also includes a Switch.
Norm Radder wrote:The problem with using Toasts is that the output can't be copied from the logcat and pasted it here so we can see what is happening.
Another possible problem is the use of literal Strings in the put and get methods. There should be one final String defined that is used in both places to make sure the same value is used in both places.
Same for the request code: it should be a final int, not hardcode literals in different places in the code.
Norm Radder wrote:Seeing these bits and pieces of code that don't go together makes it hard to suggest what the problem is.
These have different id Strings:
Pete Letkeman wrote:A few items if I may.
Instead if using Toast, you logcat as Norm has already suggested. Android Studio (and possibly other Android development environments) make this easy to do.
You can do this with as noted here https://developer.android.com/studio/debug/am-logcat.html and here https://developer.android.com/reference/android/util/Log.html.
Within Android Studio, there is even a short cut for this, just type logd then press the tab key.
There is an limit to the amount of data that can be sent using the putExtraXXX methods as noted here https://www.neotechsoftware.com/blog/android-intent-size-limit.
It is therefore recommended that you put small objects when using putExtraXXX methods.
Instead of placing an array/arraylist in a bundle and sharing that, create a temporary file or database entry and place the path to that in the bundle.
Do you know the approx size of the array/arrayList?
I think that Norm mentioned this, but it can be hard to keep track of numbers like . It is usually easier to do something like this:
Doing something like that you can not only share the codes if you need to, but you can quickly change the values without do that many find and replaces.
Pete Letkeman wrote:Sorry I forgot that you must used String.valueOf when dealing with the Android logger.
What if, simply for testing you did
Instead of If this change gives you the data you are expecting then you have a problem somewhere else with how selectedApps is being used/created.
Over here https://stackoverflow.com/questions/6543811/intent-putextra-list they mention that one option could be to use getSerializable. However they also say that what you have should work.
Norm Radder wrote:The message text's should be unique so you can tell which statement generated which output.
These look all the same.
nothing more than a "best practice,"
How can the value go from 1 at Switch to 0 at put? Is a new ArrayList created? Is there a Log statement for when the ArrayList is created?
I am still getting:
V/Array Size - Before put: 0
Pete Letkeman wrote:I would be curious to know what is the result of the following line if placed right before the for loop?
With a value of 0 for the ArrayList selectedApps I would suspect that the reported size of applicationsAdapter to be 0 as well.
Pete Letkeman wrote:In that case I am suspect that there is something not exactly correct with applicationsAdapter.getSelectedApps().
Effectively the for loop which you have as
Norm Radder wrote:
I am still getting:
V/Array Size - Before put: 0
Is that all that is printed by the Log statements?
Why are you filtering out any of the print outs?
Does this ever get printed: Array Size - Switch off
The debug print outs should have a full history of the state of the ArrayList:
When it is created
when any change is made to it: adds and removes
When its contents are accessed
Norm Radder wrote:What other accesses to the ArrayList happen before line 11 and between line 11 and line 17?
Norm Radder wrote:When is the statement that prints this: V/Array Size - Switch on: 1 executed?
Pete Letkeman wrote:Adam, can we start at the beginning? Maybe I can sum up what is happen here, please correct me if I'm wrong.
1) You suspected that there was a problem with an ArrayList loosing it's data.
2) Recently we discovered that the actual problem was not with the ArrayList, but the Adapter feeding the ArrayList.
3) You are using a ListView?
4) You are working on creating some sort of Launcher for Android
What kind of adapter are you using? It could be a RecycleViewAdapter, but it could be a different adapter such as an ArrayAdapter or some other kind?
Here is a sample/tutorial on the ArrayAdapter http://abhiandroid.com/ui/arrayadapter-tutorial-example.html.
I would recommend that you use the RecycleView which does support at least Android 4.4 (KitKat).
Eveything that a ListView can do a RecycleView can do.
RecycleView also has features that are not found in ListView like the built in Holder class/pattern.
Currently you are trying to implement an onClick event in the holder which you have attached to the adapter. Is this correct?
Is all of what I've stated above in this post correct?
------------ Unpaid Book Promo ------------
I can tell you from experience that in the book Android Programming: The Big Nerd Ranch Guide (3rd Edition) found here
https://www.bignerdranch.com/books/android-programming/ which you can see on Amazon.com here
They walk though a tutorial in one of the chapters giving you the code create your own custom Android launcher.
Not only that they provide you with a primer on using SQLite, Fragments, Activities and more.
You could get the PDF version of this book and be on you way very quickly with not only the project that you are currently working on, but other projects.
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your databasehttps://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database