- Use a static variable to process the
View cache. - Use
AsyncTask not to slow down the beginning of Activity - Use
LayoutInflater to inflate View layout and cache - In
onCreate() target activity, set the cache
Something like that:
Origin of activity
... //noinspection unchecked new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { LayoutInflater inflater = (LayoutInflater) MainParentActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // VERY VERY SLOW action if your Activity is heavy DialerActivity.cachedView = inflater.inflate(R.layout.dialer_portrait, null, false); return null; } @Override protected void onPostExecute(Void aVoid) { Intent intent = new Intent(MainParentActivity.this, DialerActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(intent); } }.execute(); ...
Target activity
public class DialerActivity extends MainParentActivity { static View cachedView = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (cachedView != null) { setContentView(cachedView); } else { setContentView(R.layout.dialer_portrait); } } . . .
You can also use the ProgressDialog during bloat to avoid freezing on transition.
source share