0

I am working on an app which on moving from Activity "A" to another Activity"B" shows black screen for 2 to 3 seconds.

I am performing calculation on huge amount of data in Activity "B", so on moving to Activity "B" due to load on mainUI it gives black screen to load.

But when i move my calculation method to OnStart or OnResume still the black screen remains.

What i want to do is show the Activity B instantly without black screen, and show loading progress while calculation is being done.

Tried threads but did not work and Async does load animation of loading but gets stuck as only animation is visible for more than 2 minutes, so any better way of moving from Activity"A" to Actvity"B" with out delay.

Did not put code because alot of code in Activity B.

Similar issue like this link Similar issue

This link also describes my problem of moving from one activity to another instantly and yes i have used async task with runnable UI thread , my async will instantly open new activity but there is too much work being done in Async do in background so i only see loading for more than a minute, with out async only 2 seconds.

RKRK
  • 1,284
  • 5
  • 14
  • 18
dan walker
  • 31
  • 8
  • 1
    You cannot put the calculations in `onCreate(), onStart()` or `onResume()` because all of these methods are called BEFORE the screen is shown. You need to perform your calculations in a background Thread and then update your UI. Your claim that running your calculations in the background take 2 minutes but running them in the foreground takes 2 seconds can't be right. Please add some debug logging that times the calculations and run this for both foreground and background. – David Wasser Apr 26 '19 at 13:23
  • Well when moving from activity A to activity B on main thread the UI hangs for 5 seconds approximately but when using async task and performing calculation it takes time depending upon calculation ,if number of files are 1000 then 12 seconds and if 2000 files then it increases time about 22 seconds.but on main thread calculation is faster. – dan walker Apr 27 '19 at 10:58
  • Also now instead of black screen my previous activity hangs for 5 seconds and then move to New activity, so at least it is showing previous activity and during this hang I want to show user loading animtion while previous activity at background,how to show aniamtion while hanging. – dan walker Apr 27 '19 at 11:01
  • You should be able to start a background thread to do your calculations and have `Activity` B display a progress dialog or animation (start this in `onResume()`) until the calculations complete. When the calculations complete, dismiss the progress dialog. – David Wasser Apr 27 '19 at 12:00
  • `Tried threads but did not work` you might want to be more specific. – EpicPandaForce May 28 '19 at 12:42

0 Answers0