0

Helo,

I've got activities, which do internet related work.

when I've got a slow internet connection, starting a new activity turns into black screen and after some seconds it will be displayed.

Internet work is done by AsyncTask.

How can I avoid this by using for example a progressbar?

ubik
  • 95
  • 2
  • 10
  • 1
    Check if most of your code is in onCreate. Ideally only static initialization should be there. rest in onStart. If your internet task is necessary to show data on screen, start indicator in onPreExecute. – Kapil G Oct 09 '17 at 14:39
  • Is there a possibility to display a progressbar between activities? – ubik Oct 09 '17 at 14:53
  • It wont make sense. Progressbar is attached to a view which would be either of activity 1 or 2. Plus the time taken to switch between activities is not that high. The delay and black screen would be coming because of some operation that takes time and is written in onCreate. Try printing the timestamp as the first line of onCreate to see how fast the activity loads and then where is the delay. – Kapil G Oct 09 '17 at 14:57
  • If your internet work is being done in a `AsyncTask` then slow internet should have no effect on activity load times. Please post your code, otherwise anything we do to help will just be a guessing game. – Barns Oct 09 '17 at 15:33

1 Answers1

0

Android is supposed to update the GUI at 60 fps. This basically means that any operation that could take longer than 16 ms should not be executed on the main GUI thread.

Your activity creation should be a quick process, relying on default values or quickly accessible data. Any "long" operation, like network, database and file system access, should be executed asyncronously using a worker thread or an AsyncTask.

Take a look at the Docs

corradolab
  • 718
  • 3
  • 16