i'm writing a questionnaire/survey type app and i need some help with the conceptual design.
i want my app to display 10 random questions selected from about 50 questions. Now I have a class:
public class Question {
public String questionText;
public string answerOptions;
}
What I am confused about is how do I get the 10 questions from the 50 questions?
1)Should the 50 questions be in a SQL database which I "grab" data from and populate my survey as required? In this case how do I a bundle the database with the apk?
2) Initialise 50 Question Objects in the MainActivity and just use them as variables?
I would save them in a normal text file.
Add the 50 questions to an ArrayList. Create a new Array of int with the size of 10 objects.
Add 10 random numbers to it (in the range of 0 - 49, Java: 50 * Math.round()) and before adding one, check whether it is already in the Array. If it is, get another number.
Then get your 10 questions from the list.
I would go for shared preferences rathet it ll save the time
And to be more presice i would suggest using javq.util.Random and call the nextRandom(50) method but remember to check if you havent alread recieved the number
Rest you can follow the above method
Sent from my GT-S5302 using Tapatalk 2
sak-venom1997 said:
I would go for shared preferences rathet it ll save the time
And to be more presice i would suggest using javq.util.Random and call the nextRandom(50) method but remember to check if you havent alread recieved the number
Rest you can follow the above method
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
Well, if I got him right, he wants to save them and include them into the apk. He asked how to do that. So there is no need for SharedPreferences.
Maybe your method for the random number is better. To be honest, I have never used that method.
nikwen said:
Well, if I got him right, he wants to save them and include them into the apk. He asked how to do that. So there is no need for SharedPreferences.
Maybe your method for the random number is better. To be honest, I have never used that method.
Click to expand...
Click to collapse
I did mean your method.was wrong or something i was just telling an easier method to implement your method in code
Sent from my GT-S5302 using Tapatalk 2
nikwen said:
I would save them in a normal text file.
Add the 50 questions to an ArrayList. Create a new Array of int with the size of 10 objects.
Add 10 random numbers to it (in the range of 0 - 49, Java: 50 * Math.round()) and before adding one, check whether it is already in the Array. If it is, get another number.
Then get your 10 questions from the list.
Click to expand...
Click to collapse
Even though it is only 50 questions now, that would over time be increased to <1000 questions. For what number will a text file be deemed "inefficient" or difficult to work with?
prtbrown said:
Even though it is only 50 questions now, that would over time be increased to <1000 questions. For what number will a text file be deemed "inefficient" or difficult to work with?
Click to expand...
Click to collapse
It would entirely depend on file size and targeted device for instance a device like mine with.300mb ram and 832Mhz proc would crawl to process a 5 mb file while a nexus 4 will do it like a breeze
I would suggest deviding the questions in sets like quesSet1 ,quesSet2 etc
Sent from my GT-S5302 using Tapatalk 2
Related
Hi,
What's the best approach to load a listview contents from a backend-server (internet)? I mean, I want to populate on-the-go a listview that will retrieve data from a internet server. For example, I want to know all orders from my e-commerce from my app, and I have like 5000 orders in the last week, I won't load this 5000 orders because my app will have a great load time and memory consumation.
My idea is load more when user get close to the last element of list, but I don't know how to do this, and about memory consumation? Is better to continue with the data in memory (when user goes back to upper), or save it on a file-cache (better than memory?) and load when user scroll back to the top?
Thanks,
While the user is the activity you must hold each of the list item in memory anything other than that will cause serious lag in your app
While at other times you may cache them to save resources
Sent from my GT-S5302 using Tapatalk 2
You definetely need ASyncTask here. You can define a class as asynctask, which lets you implement a few methods to use as a background thread. So whenever you wan to load more items you can call this background thread which does not block the UI.
Also, if I remember correctly, you can implement a method which lets you know which list item is at the top of the screen, the total number of items in the listview, and the number of items on the screen.So with this method you can find out whrn you reached the last item in the listview.
I hope this helped a little, at least you got some stuff to google
Sent from my NexusHD2 using xda app-developers app
Ya as he said use a global variable and update it in getView if adapter hence ull know the last loaded view
Sent from my GT-S5302 using Tapatalk 2
I am trying to pass data from activity 1 to activity 5 without using Intent. How can I do that? The data type is string.. Is there anyway I can make a class between them which handles the data?
Not a really nice way, no. The simplest to do is with intents and if you want to pass something back with the startActivityForResult(intent) and then overriding onActivityResult.
Another possibility is to save the string in a text file and then open it from the other activity.
And Google is our friend: you can do this
using a class with a lot of static variables (so you can call them without an instance of the class and without using getter/setter)
Click to expand...
Click to collapse
Which means you create your class just with static variables and methods and access them without creating an object. But I don't think that's a good way to do it, if you have a simple String, do it with an Intent.
I agree that you should not do this.
If you still want to do this, use SharedPreferences.
nikwen said:
I agree that you should not do this.
If you still want to do this, use SharedPreferences.
Click to expand...
Click to collapse
Well, read this, see if EventBus could solve your problems:
http://xenoamp.info/index.php/capta...-eventbus-a-k-a-intents-you-shall-not-paaasss
I think that using eventbus is the cleaner method
Sent from my SK17i using xda app-developers app
ssuukk said:
Well, read this, see if EventBus could solve your problems:
http://xenoamp.info/index.php/capta...-eventbus-a-k-a-intents-you-shall-not-paaasss
Click to expand...
Click to collapse
Skektox said:
I think that using eventbus is the cleaner method
Sent from my SK17i using xda app-developers app
Click to expand...
Click to collapse
Makes sense.
ssuukk said:
Well, read this, see if EventBus could solve your problems:
http://xenoamp.info/index.php/capta...-eventbus-a-k-a-intents-you-shall-not-paaasss
Click to expand...
Click to collapse
way too nerdy for me.. I haven't started with broadcasts yet..
SimplicityApks said:
Not a really nice way, no. The simplest to do is with intents and if you want to pass something back with the startActivityForResult(intent) and then overriding onActivityResult.
Another possibility is to save the string in a text file and then open it from the other activity.
And Google is our friend: you can do this
Which means you create your class just with static variables and methods and access them without creating an object. But I don't think that's a good way to do it, if you have a simple String, do it with an Intent.
Click to expand...
Click to collapse
See here's the structure of my app:
activity 1: take input
activity 2 : choose game
activity 3: choose difficulty
activity 4 : start game
activity 5: scores displayed with the name entered in activity 1
If I use:
Code:
name=edittext.getText().toString();
Intent i= new Intent( activity1.this, activity5.class);
Bundle user = new Bundle();
user.putString("key", name);
i.putExtras(user);
startActivity(i);
It would immediately start activity 5 which I dont want...So what should I DO?
For récords you need persistence. Use XML files stored in application Folder (search for getexternalfiledirectory or something similar). Instead, you can use sqlite database, I think it's the best option.
Cheers
Sent from my SK17i using xda app-developers app
First of all, I wouldnt use so many activities, that's why dialogs were invented... They are a lot simpler to use because u can pass the values back. If the name the user enters is always the same (I guess so) you should save it in the SharedPreferences. This way you can also edit it in your SettingsActivity.
If you really want to do it with five activities you could still put everything in a Bundle and pass the Bundle through all the activities with intents if every activity gets the bundle from the last one and puts it to the intent to start the next one.
SimplicityApks said:
If you really want to do it with five activities you could still put everything in a Bundle and pass the Bundle through all the activities with intents if every activity gets the bundle from the last one and puts it to the intent to start the next one.
Click to expand...
Click to collapse
Yes I thought of it. Would be really tiring.
I am tryin to fix an app created by someone else so I need to follow the main framework of his app
prototype-U said:
way too nerdy for me.. I haven't started with broadcasts yet..
Click to expand...
Click to collapse
Don't start with them, they're not worth it!
Sent by automatic reply bot from my Galaxy S2
prototype-U said:
See here's the structure of my app:
activity 1: take input
activity 2 : choose game
activity 3: choose difficulty
activity 4 : start game
activity 5: scores displayed with the name entered in activity 1
If I use:
Code:
name=edittext.getText().toString();
Intent i= new Intent( activity1.this, activity5.class);
Bundle user = new Bundle();
user.putString("key", name);
i.putExtras(user);
startActivity(i);
It would immediately start activity 5 which I dont want...So what should I DO?
Click to expand...
Click to collapse
If you really want the full screen display without using dialogs, then fragments with a viewpager would be your go-to.
A pager with multiple fragments using the fragment manager to replace each fragment into your content view is ideal.
That way, you're contained within 1 activity and don't need to pass data between fragments if you tie it back to the activity.
prototype-U said:
See here's the structure of my app:
activity 1: take input
activity 2 : choose game
activity 3: choose difficulty
activity 4 : start game
activity 5: scores displayed with the name entered in activity 1
If I use:
Code:
name=edittext.getText().toString();
Intent i= new Intent( activity1.this, activity5.class);
Bundle user = new Bundle();
user.putString("key", name);
i.putExtras(user);
startActivity(i);
It would immediately start activity 5 which I dont want...So what should I DO?
Click to expand...
Click to collapse
Well I'm not sure if you want the app to be like this, but you could try to pass the string along every activity. Like this:
Activity1 starts activity 2 while passing the string.
Activity 2 starts activity 3 while passing the string, etc until you reach activity 5.
The only problem is that you would need to go through every activity.
Sent from my awesome fridge
prototype-U said:
See here's the structure of my app:
activity 1: take input
activity 2 : choose game
activity 3: choose difficulty
activity 4 : start game
activity 5: scores displayed with the name entered in activity 1
If I use:
Code:
name=edittext.getText().toString();
Intent i= new Intent( activity1.this, activity5.class);
Bundle user = new Bundle();
user.putString("key", name);
i.putExtras(user);
startActivity(i);
It would immediately start activity 5 which I dont want...So what should I DO?
Click to expand...
Click to collapse
I know this isn't the best option or a reliable one but try a static field declared as public in the class where you take inputs and access them when you need it
Sent from my GT-S5302 using Tapatalk 2
I am not sure about ur Problem, But here is guide
One more best way to send data from one activity to other as well as Send data to main thread from other thread
is Handler U can send messages to Static handler of a activity from any of ur application...
Its so far best way i followed to alter my UI as well send data from Background service to my Main activity
CoolMonster said:
One more best way to send data from one activity to other as well as Send data to main thread from other thread
is Handler U can send messages to Static handler of a activity from any of ur application...
Its so far best way i followed to alter my UI as well send data from Background service to my Main activity
Click to expand...
Click to collapse
However, that is bad practice. What if you need two Activities like this at the same time?
Additionally, the Handler will be running in the background, even after the Activity is destroyed.
Hallo everbody,
im writing a background service to get informations like the time an active app (not my app) is running.
With this information i can show the user a list of the most used apps depending on the time.
The methods of the ActivityManager-class are useless, because the received informations aren't reliable.
So i thought, because the Android-System is based on a Linux-Kernel, i can use the internal structure to get these informations.
So i read out the pseudo proc-filesystem to get the process informations and for the 2nd time i thought
thats the right place for me to get what i want.
I read out the stat-file in every single process-directory to get the starttime(in clock_ticks) of the process.
I dynamic calculate the HZ USER_HZ value and use it to get the real starttime but this time never changes.
It's more like a timestamp of the first start on the system after boot.
The user-code-time and kernel-code-time seems to be too short and the values are updated too irregular.
So i just got a time value, that tells me the time when the app was first started after system boot
but i want a timestamp or anything else i can get from a currently running app to calculate the time this app is active.
Long life services and background services are not my goal.
Now i'm here because i don't know if i just miscalculate the values from this pseudo filesystem or
if i'm absolutely wrong where i get my informations from.
My Questions:
1. Do i read the wrong values files filesystem (if yes, where can i find these informations in the system structures)
2. Do i misunderstand some of the values i read out
3. Why do the files in the process directories become updated so irregular or once in a lifetime (just if im in the right filesystemfile)
I hope u can help me. *-*
Well, interesting approaches. :good:
The only way I see is running a background service and storing the launch time yourself.
I'm sorry but I don't know the answers to your questions.
You could
a) use su to get the active process list
b) get to /proc/??? folder (where ??? is the apppropriate process you enquire, for example /proc/80/)
c) get the /proc/80/sched text file and look for exec_runtime or vruntime or what ever works for you
carbonpeople said:
You could
a) use su to get the active process list
b) get to /proc/??? folder (where ??? is the apppropriate process you enquire, for example /proc/80/)
c) get the /proc/80/sched text file and look for exec_runtime or vruntime or what ever works for you
Click to expand...
Click to collapse
Oh, getting the currently running tasks can even be done much easier and doesn't require root. This is what I use:
Code:
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> processInfoList = am.getRunningAppProcesses();
carbonpeople said:
You could
a) use su to get the active process list
b) get to /proc/??? folder (where ??? is the apppropriate process you enquire, for example /proc/80/)
c) get the /proc/80/sched text file and look for exec_runtime or vruntime or what ever works for you
Click to expand...
Click to collapse
that seems to be exactly what i need!
but there are the next questions:
what is the unit of the "se.sum_exec_runtime"-field? is it in nano-secs?
what does the point do in the value? does it indicates a floating-point value?
im kinda confused and didnt really find something meaningful about the unit (*-*)
and im not very handy with the kernel code from "lxr.linux.no"
nikwen said:
Oh, getting the currently running tasks can even be done much easier and doesn't require root. This is what I use:
Code:
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> processInfoList = am.getRunningAppProcesses();
Click to expand...
Click to collapse
Following Note can be found in the android-doc:
"this method is only intended for debugging or building a user-facing process management UI."
And the "RunningAppProcessInfo"-class (given by the Method) doesnt provide any infos about the running time of a process.
So i think it's more reliable for me to read out the process-infos directly in the proc-filesystem.
Dalorikai said:
Following Note can be found in the android-doc:
"this method is only intended for debugging or building a user-facing process management UI."
And the "RunningAppProcessInfo"-class (given by the Method) doesnt provide any infos about the running time of a process.
So i think it's more reliable for me to read out the process-infos directly in the proc-filesystem.
Click to expand...
Click to collapse
1) True.
2) That's why I wrote this:
nikwen said:
The only way I see is running a background service and storing the launch time yourself.
Click to expand...
Click to collapse
3) But if the other method works and if you don't care about root rights as a requirement, it might be better. :good:
Dalorikai said:
what is the unit of the "se.sum_exec_runtime"-field? is it in nano-secs?
what does the point do in the value? does it indicates a floating-point value?
im kinda confused and didnt really find something meaningful about the unit (*-*)
and im not very handy with the kernel code from "lxr.linux.no"
Click to expand...
Click to collapse
replying to my own post i think the point in the value of the field indicates the milli-secs.
just an idea - im not sure but would be plausible if the unit is nano-secs.
what do u think or possibly know? ^^
Hello,
I'm editing an app using APKGUI, mostly to modify the look to conform more to holo style. I would, however, like to modify it a little. It is a messaging app and i want to put pictures of those who sent the message next to the message (line in hangouts) but I can't get it to work by editing the XML. Is there any way to do this through APKGUI modifications or not?
Thanks.
Nickcu13 said:
Hello,
I'm editing an app using APKGUI, mostly to modify the look to conform more to holo style. I would, however, like to modify it a little. It is a messaging app and i want to put pictures of those who sent the message next to the message (line in hangouts) but I can't get it to work by editing the XML. Is there any way to do this through APKGUI modifications or not?
Thanks.
Click to expand...
Click to collapse
depends on the app but I would suspect not as you would need code to resolve from a content provider to then populate the item (ImageView) in the row. So that would be in the adapter code powering the listView in the app
deanwray said:
depends on the app but I would suspect not as you would need code to resolve from a content provider to then populate the item (ImageView) in the row. So that would be in the adapter code powering the listView in the app
Click to expand...
Click to collapse
is there any way to get into the code?
Nickcu13 said:
is there any way to get into the code?
Click to expand...
Click to collapse
yeah if it's not too obfuscated when decompiled and you know how to query a content provider and load images, maybe not doing said actions on the ui thread but on another thread.. use smart messenger instead when I'm done you will be able to create a UI to your own needs </shamelessplug>
deanwray said:
yeah if it's not too obfuscated when decompiled and you know how to query a content provider and load images, maybe not doing said actions on the ui thread but on another thread.. use smart messenger instead when I'm done you will be able to create a UI to your own needs </shamelessplug>
Click to expand...
Click to collapse
basically all i need to do is get to the coding of one section where the profile image is displayed, and copy the query into the new section. but i don't know how to do that or where to find it in the decompiled part. It's not a normal messaging app, it's more of a people discovery app with messaging haha.
Nickcu13 said:
basically all i need to do is get to the coding of one section where the profile image is displayed, and copy the query into the new section. but i don't know how to do that or where to find it in the decompiled part. It's not a normal messaging app, it's more of a people discovery app with messaging haha.
Click to expand...
Click to collapse
it is not really a copy paste and work job Or that would be like, 0.0001% probability of working
deanwray said:
it is not really a copy paste and work job Or that would be like, 0.0001% probability of working
Click to expand...
Click to collapse
and why is that?
Nickcu13 said:
and why is that?
Click to expand...
Click to collapse
cause you would possibly need the following, get the contact id from the row from xxx variable/data, construct the now unique uri to pass to a content resolver to lookup the image uri and or path, then get an instance of the row imageView (or whatever view was going to hold the image) then pass that to a loader/async/new thread along with the uri for that then to load in the background, then check that when loaded the imageView instance is still the same (due to the way android recycles views) before setting it back on the main ui thread.
So a recap on the variable/s
imageView
contact id source (of that row)
the instance and data tracking in a thread
so these things are not something you can find in one app or even from the same app and "paste" into another section.
hope that, well, makes enough sense to know it's not a copy paste thing
deanwray said:
cause you would possibly need the following, get the contact id from the row from xxx variable/data, construct the now unique uri to pass to a content resolver to lookup the image uri and or path, then get an instance of the row imageView (or whatever view was going to hold the image) then pass that to a loader/async/new thread along with the uri for that then to load in the background, then check that when loaded the imageView instance is still the same (due to the way android recycles views) before setting it back on the main ui thread.
So a recap on the variable/s
imageView
contact id source (of that row)
the instance and data tracking in a thread
so these things are not something you can find in one app or even from the same app and "paste" into another section.
hope that, well, makes enough sense to know it's not a copy paste thing
Click to expand...
Click to collapse
so if it does all that once, all i need to to is copy and paste it, then change the variables to be unique.
Nickcu13 said:
so if it does all that once, all i need to to is copy and paste it, then change the variables to be unique.
Click to expand...
Click to collapse
well no, each one of those happens for every row, also you would have to "find" the data and instances to make it happen. example would be simply finding the resource ident (integer) for the imageView and grabbing an instance of it. findViewById(R.id.someIDofImageView) but then to avoid constant findViewById lookups on recycled views you would use a viewholder pattern, that then you would create a new object class that would hold this (cause lookups for the same ident on the same row many times when scrolling would not be great)... and more stuff, and thats just for the imageView instance part... clearer ?
I guess my point would be it's more involved that you perhaps think it is. Specially if you know little or no android/java
deanwray said:
I guess my point would be it's more involved that you perhaps think it is. Specially if you know little or no android/java
Click to expand...
Click to collapse
Another thing not to forget is the APK signature. If you unpack, edit and repack an APK you must sign it, othewise the installation will fail.
Hey Guys,
I am creating a app to rename other apps via xposed and the main code is written. Now I simply want to make a interface where you can define a app to rename and then enter a new name. For the beginning I thought about a Activity where you enter the Package Name and the desired name. Later on I want to use a list view to show all apps, from where you can choose one to rename(Like App Settings etc.). To show the renamed apps I want to use a ListView. Now I am stuck with a problem: My xposed code works with an array to check and rename. The list view can be used with an array or an arraylist, but I need a way to store the preferences(which are stored in a array).
Do you have a good idea or a sample how to realise this? And does somebody know a nice App List type of thing(I googled, but the project there aren't usable with my kind of approach.)
GalaxyInABox said:
Hey Guys,
I am creating a app to rename other apps via xposed and the main code is written. Now I simply want to make a interface where you can define a app to rename and then enter a new name. For the beginning I thought about a Activity where you enter the Package Name and the desired name. Later on I want to use a list view to show all apps, from where you can choose one to rename(Like App Settings etc.). To show the renamed apps I want to use a ListView. Now I am stuck with a problem: My xposed code works with an array to check and rename. The list view can be used with an array or an arraylist, but I need a way to store the preferences(which are stored in a array).
Do you have a good idea or a sample how to realise this? And does somebody know a nice App List type of thing(I googled, but the project there aren't usable with my kind of approach.)
Click to expand...
Click to collapse
Ah the data storage problem... I think we all came across this at least once . I suppose you read this guide on the different options available? Well there are actually three options: SharedPreferences, text or csv file and SQL.
The first one would need some work around and is probably the slowest. You would save a separate string directly into the SharedPreferences (maybe in a new file to avoid collisions?) with the array name and its index somehow in the key. That's just two methods of coding but not the nicest way to do it.
The text or csv file however is the more common way, here you'd save your array in one line of the file, each item separated with a ; or some other char. Needs a bit more coding and also the WRITE_EXTERNAL_STORAGE permission on preKitKat if I remember correctly.
The third one is the nicest and most modular one. Because it makes use of SQL it needs quite a bit of knowledge and some coding (but less than the text file).
I guess for simple things that you want to do it is better to stay away from SQL for now unless you know how to use it and use the SharedPreferences.
Edit: take a look at the answers to this question, they give you the code as well... And you can use StringSets in ICS and above if the order of your list doesn't matter !
I'd say go down the SQLite DB way, chances are that if you plan on expanding your coding knowledge and want to keep creating apps you'll be needing to learn this in the future anyway so why delay?
Google AndroidHive and look at their SQL tutorial - I used it when learning and found it very informative
Sent from my HTCSensation using Tapatalk
Thank you very much! As coming from windows, first of all I thought about SQL as well, but it seems oversized for the set of data i want to store. I also took a look at the stackoverflow thread you linked. It looks easy to implement, but the need to use an external class file made me look for another way. I found this one, which works pretty well for me, as I look forward to interchange the method of saving the data with a better one using the SharedPreferences(which actually should be really easy with my code).
Maybe you can tell me yet another thing: Is there a way of declaring an object(like the ArrayList) to make it accessible from every class except from giving every class(activity) it's own "load the preferences" and "save the preferences" code block or sending intents all over the place? This would make saving much easier and allow me to update the preferences during runtime and without a reboot
Edit: This was my answer to.SimplicityApks ^^ I'll take a closer look at SQL now, since you, Jonny, told me that it' nevertheless necessary.
GalaxyInABox said:
Thank you very much! As coming from windows, first of all I thought about SQL as well, but it seems oversized for the set of data i want to store. I also took a look at the stackoverflow thread you linked. It looks easy to implement, but the need to use an external class file made me look for another way. I found this one, which works pretty well for me, as I look forward to interchange the method of saving the data with a better one using the SharedPreferences(which actually should be really easy with my code).
Maybe you can tell me yet another thing: Is there a way of declaring an object(like the ArrayList) to make it accessible from every class except from giving every class(activity) it's own "load the preferences" and "save the preferences" code block or sending intents all over the place? This would make saving much easier and allow me to update the preferences during runtime and without a reboot
Edit: This was my answer to.SimplicityApks ^^ I'll take a closer look at SQL now, since you, Jonny, told me that it' nevertheless necessary.
Click to expand...
Click to collapse
Welcome
You mean you want to make your ArrayList, which is an instance variable in the activity, accessible to every other class within your package without having an instance of your activity at hands? Well the basic solution would be to make the ArrayList static. But that is not recommended because it won't be created and garbage collected at the same time as your activity and also it's not a nice way .
If you had an instance of the activity it would be just using a public getter for it, but without I'd put your ArrayList into a separate class following the Singleton pattern. That way you have only one global instance which contains the ArrayList.
Thanks again for your reply! I changed my mind about the ArrayList and created a method, where everything is stored in the SharedPreferences and the ArrayList's only purpose is the use with the ListView and Adapter. This way I don't have to write the ArrayList to the SharedPreferences and changes will be much easier to control. Although I had to implement another type of save/load method to interact with the class thats being loaded by xposed. That was needed because of the restriction that you can only load SharedPreferences with a context, which my class doesn't have. It's an inconvenient way, but it works