How to start Activity immediately?

39 Views Asked by At

I have an activity that starts a Java method from another class. In this class I start another activity that contains a WebView to read data from a Java Script website.

I use startactivity for this. But when I run startactivity it doesn't jump into OnCreate from the activity, but only at some point later. How can I start an activity and wait for it to be processed straight away?

It doesn't work with StartActivityForResult either.

1

There are 1 best solutions below

0
snachmsm On

Activity is starting as soon as possible always and never "immediatelly". Activity must initialize itself and "sync" with system (its lifecycle), which takes time, few millis on fast devices, dozens and maybe even hundreds on weak units

you aren't helping using most heavy and inefficient compontent in system - WebView. even more, you are executing JS in it

maybe some workaround would be to use single Activity and switching Fragments. one Fragment may be native and visible on start (will be inited and rendered pretty fast), another may contain WebView and will be loaded on Activitys start, but invisible. instead startActivity you may then switch visiblity of Fragments - one with WebView is in fact already loaded in memory at Activitys start, should appear much faster