Currently I'm receiving a JSON from a server with updated information on a contact. Currently, I iterate through the JSON and do an update on my app on the phone, but for 2000 contacts, it takes up to 50 seconds(I used transactions too, b4 that it took 70 seconds). Is there a faster way to speed this up?
Well, just remember that it's 2,000 row updates, and on a handheld phone/tablet. It's not a high-powered server with an in-memory database. This stuff takes time. Unless you're doing something more than what you're saying, it doesn't sound like you're taking more steps than required (i.e. there's nothing to cut out in order to save time)
Often performance is just as much perception, as it is optimization. One way to deal with this reality is to simply return control of the UI to the user, making your app look snappy and responsive, while doing the contact updates in another thread in the background. That would give your app the appearance of being very fast, even though it still takes 50 seconds to complete all the updates.
Are you using Android's built-in JSON objects? If so, that may be the source of the performance problem. The first time I profiled my app, I was surprised to find that JSON parsing was causing the biggest performance hit (see also this post in the Android Developers Blog).
You should profile your code to find exactly what is taking the most processing power then perhaps you may be able to find a more efficient solution to your problem
Profiling on Android is done making a tracefile on view, then viewing it with Traceview.
See here for detailed information
Related
I am currently trying to read data from an android app, to do so I am using Bluestacks 5 Nougat-32 bit, and GameGuardian. I have found the address of the data I am trying to find although every time I restart the app the address for this data changes. I was wondering if there is any way to figure out these addresses automatically (or to have them in a set position)?
The method I am currently using it to look up the known value of the data, which gives me hundreds of results in GameGuardian, I then alter this value by a known amount and run a query for addresses which have changed by this exact value. This then allows me to get the address. Although I am looking to automate this process (I am building an inventory management system for online games, and this data feeds into a much larger automated process - I currently have it working using OCR but this method would reduce computing power needed, and increase speed.
For example, on first test I got the following addresses for the 4 pieces of data I am looking to read:
9285E5B0
9285E058
9285E5B8
9285E5C0
After restarting the app, I got these values:
7F38C5B0
7F38C5A8
7F38C5BB
7F38C5C0
And this changes every time I restart the app. Any suggestions please how I can get these values automatically? The only method I can currently think of is creating a script to automate what I am doing manually, although this is extremely impractical when scaling (as would require image recognition etc to change the values to determine their addresses).
Please note, I do not own the app or anything so can't inject code from that side (can't inject code at all obviously as trying to not break the law, I just want to read the data).
Thank you in advance :)
What I have tried so far:
I have tried using GameGuardian to read the addresses - and this has worked.
Every time I restart the app the addresses change, which means I am struggling to automate the process. I have made a note of lots of restarts and can't find any pattern in how it allocates the addresses. I was hoping that the address would remain the same even after the app restarts.
Edit: I am toying with the idea of running python on the android emulator, and doing the OCR on the emulator itself and sending the data to a server for it to then be analysed for the inventory management system. My issue with this is again how much computing power would it take - but it would at least cut down (or so I would imagine) on my current solution which is a macro that takes a screenshot, uploads it to DropBox, then server downloads the image from DropBox and performs OCR to then be used in the inventory management system.
I have been working on an android project that has a feed similar to Instagram/Facebook and I am trying to figure out the best strategy for consuming the data from my database.
Specifically I am wondering if I should query all the data at once (assume 50 records +) or if should I perform queries as the user scrolls -- grabbing so many records at a time. If the ladder, about how many posts/records should I get per query assuming the content/size is similar to that of a Facebook post.
I've spent a descent amount of time researching this issue and haven't come across anything so any suggestions would be much appreciated. I do apologize if this issue has already been addressed and if you could you just post the location of the answer that'll work too.
Thanks in advance!!
Fetching all the data can be too much at times and your app will have very slow response time, that why it's better to load some data at a time and just add it as you get it. In my opinion it's best to load 2 screens of data at a time, so try and see how many posts you can have in a screen and get x2 (if on one time you can see 5 posts, load 10 at a time) or load for example 10 at the first time and 5 each next time. This truly is your preference as I think.
If this is the method you want to use keep in mind that there are different screen sizes for android (from android wear to different sized mobile phones, tablets and smart tv-s) so try making different methods for each group if devices. You can maybe have an abstract class (or interface) with the method and have every other class for different size extend or implement (regarding of using class or interface) to make the code more well written, easier to change and reusable.
But all in all it's in your hands and you can make it by your liking. Hope this helps, and gives you some matter to wrap your head around.
I am working on an application that Looks similar to the Google Play App (swipe view with gridviews inside the fragments, in addition data in the gridview [image + text] is retrieved from a remote server).
My problem is with background tasks. I can’t decide what to use for retrieval of data from the internet. Mainly I am trying to decide whether to use AsyncTask or manual threading.
Of course it would be easier to implement AsyncTask, but after some research I noticed that many people find it limiting.
In my particular case, I want to download data from the internet as Json Objects, parse them and display the data in the gridview. The gridview would have up to 30 items, each item contains a thumbnail and 3 textviews. In Android documentation, they say that AsyncTask is suitable for short operations (few seconds at most). Would filling up to 30 items be considered as a short operation?
I want the data to be fetched concurrently. Also I want to support Android phones from API 8 and above. I read that for different APIs AsyncTask behaves differently (serially or concurrently)
My question is: Is it appropriate to use AsyncTask for my app? Or do I have to do everything manually? Is ThreadPoolExecutor a 3rd way to do this? Is it easier than manual threading?
Any advice would be appreciated, I can't move forward in the implementation without deciding on this issue.
Thanks in Advance!
My understanding is that the comment about using AsyncTasks only for short operations is aimed more at not expecting the same views to be available when a long operation finishes. For example, if a user leaves the app and comes back or the current activity goes away for some reason. Typical ways around this would be to use a Service and start up a plain old Thread there, then send some message telling the current Activity to refresh when the operation is done.
The download and processing of your data is likely to be the longest operation. So I'd use that as a basis for whether this is short or long. If you don't care about persisting data at all and don't mind restarting downloads if a user leaves and comes back, you can just use an AsyncTask with very little thought.
If you are using a GridView, you should only ever be populating enough views to for just over the number displayed on the screen at one time.
I'd say that AsyncTask is fine in your situation assuming it's a few kilobytes of data and not megabytes or hundreds of kilobytes. Megs of data, I'd say move to a Service with a Thread. Hundreds of k, is a toss up.
Also, take a look into Loaders... if you want to see an alternative that is better for this kind of loading.
When attending DroidCon in London last year, a presentation brought to my attention why using AsyncTasks for loading data from the network is unreliable.
This presentation was about the RoboSpice library.
The site also has a very nice infographic explaining why exactly AsyncTasks are unreliable and what RoboSpice does to amend these problems.
Disclaimer:
I am in no way affiliated with RoboSpice, nor have I ever tried it. I was just impressed and convinced by their presentation that it's a tool worth trying.
Friend, I am working in a project exactly as you need, and to support API 8 and above you should use Asynctask to download anything or you will get a crash for API 15 and above, because it won't even let you run your app without AsyncTask even for short operations.
So as I almost did everything that you need and it is working very well for API 9 above, you should use Asynctask, I´ve implemented SherlockActionbar, EndlessAdapter and ViewPager all with AsyncTask, so go on, if you need more help just ask again later.
So I am in need of some assistance in trying to determine what I am going to need in order to accomplish a task.
Plain and simple...I am looking at accessing multiple databases some of which may contain over 10,000 records via Android. From what I have seen web services that return JSON is the way to go for something of this nature, but I don't think that fully answers my question or know if this is the preferred way to go about this.
Digging a bit deeper...I have a few apps on the market now, but this will be my first attempt at an enterprise style app, and I have accessed public web services with a lot smaller footprint than what this is going to be. I have little to no experience within the realm of server/network administration which is where I am getting tripped up. This is from the ground up and I have to ability to obtain almost any resources I need to complete this task.
It appears that there is a SQL Server 2008 on the back end if that helps. If I need to provide further details let me know. I am looking at a solution that will handle organizational growth, scalability, authentication and ease of user...so keep that in mind too.
So what is the best practice/preferred method for doing an enterprise application with a substantial data set? What are the big dogs doing, and how? Both on the client side and server side. I am trying not to "screw the pooch" out of the gates on this, and this is one of those measure twice and cut once situations which is why I am trying to garner plenty of input and assistance.
Thanks in advance!
If you don't have an API/service yet, you need to write one on top of your database.
I can think of two approaches, depending upon your use case.
Paging: Setup an API that supports paging, and show the results page by page. The user can't possibly view 10000 records in one go.
Search and suggest: Try creating a suggestion list, when the user starts typing out something. Fetch results that start with the initial characters entered. However, the API should limit the results to a comfortable number, so that you don't have to parse a lot.
Depending on your use case, you could try one of these.
Folks, I'm trying to see if my plan realistic at all. I'm ne to
Android platform but not new to software development. This is my first
post here as well :)
We want (in our company) to create Android software to compliment our
truck management software. Basically, it will do couple very specific
tasks.
a. Send GPS updates to server.
b. Receive trip information.
c. Send pickup/delivery confirmation to server.
After evaluationg i. platform and Windows phone 7 platform we came to
conclusion that only Android has multitasking that works for us. So,
Android it is but I have some specific questions.
Data plan we want to use will be very limited. Probably 5M/mo and
no voice/text. I figured 5x1024x1024 = 5242280 bytes will give me 1k
per transmission every 15 minutes (3000 transmissions per mo). It will
leave 2M for other stuff that will happens every couple of days. Does
my math look OK or there is lot of "waste" traffic? Our server going
to be XML SOAP and messages sent will be just Lon/Lat in XML package.
1K will be OK? If I just calculate bytes it will be even less but I
wonder if there is "minimum" packet size, etc. Any insight on this
data limitation appreciated.
Because of #1 we need to "lock" device somehow so there is no other
software that uses network. Possible? If so, what do I need to look
for? I found already created app - firewall and it says phone has to
be rooted for that.
Receiving trip information. What's the best way to accomplish that
given my situation? Should I run some kind of listener? Will my phone
have IP address or something? Or should I get small text plan and use
that for this specific functionality? Can I receive text message in my
own application?
So, as you see we trying to shrink $80/mo service to $15/mo service
that will do big savings to our company but not sure if it's all
possible with constraints we have. Also, we may just give discounts to
drivers who have Android phone and will install our app but we don't
count on that.
Thank you in advance for any help on this subject.
UPDATE:
Now that I think about it - limited data plan present challenges initially but actually helps us do it "right" to make sure we don't overload server with constant polls. What I really like to see is some real-worls experience with data usage. Problem is, to us to even come up with test app - will require considerable effort. Would be much better to rule this out right now if it won't work. For example, if I knew that message size 2k no matter how big of a message itslef - then I would know immediately that it won't work for us..
If you have a very limited kind of data that you are transferring, the overhead of xml might be unnecessary. Instead, pass .csv data to different endpoints dependent upon the data that your are transfering (one endpoint for lat/lon, another for pickup/delivery confirmation)
You do have an ip address on each device, but you're not necessarily going to know that information - it's not constant, or consistent (it can change as the phone moves around). Instead, do a timed polling of the server (that would make your 3rd endpoint) See other mentioned solution of triggering on SMS.
As far as locking the device, I'm not sure about this, but it certainly seems feasible (though it's not consistent with your 'discounts to drivers who have Android phone'. I understand why, but if the phone has no voice/text capability, it's not likely that the phone will be used by the drivers for much besides it's expected purpose.
You are not going to achieve this with a default Android ROM in other words you have to create your own customized ROM from scratch and deactivate quite some stuff in order to get your devices not to use up the 5M/Month.
You can checkout the developers site on the Android source code to check out if that would be an option for you. Giving discounts to drivers owning an Android phone sounds nice and all but I'm quite certain that this is not going to get the desired results which I guess are that you equip all your trucks with such a device and track all of them.
In my opinion it is not going to work with a data plan of 5M/Month but on the other hand I don't know the data consumption numbers without testing.
UPDATE: Also I would not go with XML but with JSON due to overhead.
When you upload a GPS update, have the server reply with any of the trip data you need to push down to the phone at that time.
I think that for the data traffic (the other topics that you asked about are already solved in the other answers) using a bitmask-like solution will be the best option, first bits are for lat, the next for lon, and then some bitmask for the flags, and sending text data only if it is necessary.