0

I have a bunch of little files in my assets which need to be copied to the SD-card on the first start of my App. The copy code i got from here placed in an IntentService works like a charm. However, when I start to copy many litte files, the whole app gets increddible slow (I'm not really sure why by the way), which is a really bad experience for the user on first start.

As I realised other apps running normal in that time, I tried to start a child process for the service, which didn't work, as I can't acess my assets from another process as far as I understood. Has anybody out there an idea how

a) to copy the files without blocking my app

b) to get through to my assets from a private process (process=":myOtherProcess" in Manifest)

or

c) solve the problem in a complete different way

Edit: To make this clearer: The copying allready takes place in a seperate thread (started automaticaly by IntentService). The problem is not to separate the task of copying but that the copying in a dedicated thread somehow affects the rest of the app (e.g. blocking to many app-specific resources?) but not other apps (so it's not blocking the whole CPU or someting)

Edit2: Problem solved, it turns out, there wasn't really a problem. See my answer below.

Community
  • 1
  • 1
Kevin Gebhardt
  • 368
  • 1
  • 12

2 Answers2

0

I suggest you to create a separate thread to do the work. Or, more simple, an AsyncTask!

  • Sorry, didn't help, not to say AsyncTask seems to make the UI even slower than the IntentService. As both create a separate thread this isn't really suprising to me. I guess the slowdown must have something to do with the filesystem access, but I can't get my finger on it. As all activitys of the App are affected, it's definitly no code-problem in the other Activitys. – Kevin Gebhardt Aug 22 '14 at 11:28
  • Please note that an Android service is not a thread! It is not a means itself to do work off of the main thread, like the doc say: http://developer.android.com/reference/android/app/Service.html. And yes, this is possible that the filesystem access would be slow. What is your device? – Kevin Vuilleumier Aug 22 '14 at 11:41
  • Please note that an Android IntentService is not exactly the same as an Android Service ;) [Docs](http://developer.android.com/reference/android/app/IntentService.html). As stated there "IntentService is a base class for Services that handle asynchronous requests (expressed as Intents) on demand. Clients send requests through startService(Intent) calls; the service is started as needed, handles each Intent in turn **using a worker thread**, and stops itself when it runs out of work. " – Kevin Gebhardt Aug 22 '14 at 11:56
0

Sorry for this, it turns out you actually can use the assets in a child process. I've got no idea why it doesn't work the first time I tried it. So the answer to my question is actually (b). Create a child process for the Intentservice, access the assets through getApplicationContext().getAssets() and there you go. It now runs satisfiable fast. Thanks for trying to help.

Kevin Gebhardt
  • 368
  • 1
  • 12