Question

Many times in android apps, users click a button/view and start a new activity, where the new activity pops up in front of what the user was previously looking at, and loads data.

Would there be any difference from a user perspective if the data started loading (from network or disk or both) when the user clicked the button before the next activity started. And then that data was returned to the new activity in a broadcast receiver.

This is compared to starting the process in the oncreate of the activity. Assuming these network and i/o processes only take milliseconds either way, would it make a difference to the user if the methods were started in onCreate of the new activity, or started in the old activity onClick.

First way, starting I/O and changing views after I/O finishes

//first activity
public void onClick(View v){
     startActivity(new Intent(this, NewActivity.class);
}

//NewActivity.class
onCreate(Bundle mBundle){
   super.onCreate(mBundle);
setContentView(R.layout.mView);
mObject = networkCall();  //after network call, the view objects in this layout will reflect data from the network call

}

second way, starting the I/O in the first activity

//first activity
public void onClick(View v){
     IntentService networkCall = new IntentService();
     //start network call

     startActivity(new Intent(this, NewActivity.class);
}

//second activity on create just sets the view and also broadcast receiver

My GUESS is that in the split second that it takes for the activity to pop up, the data from the intent service could become available. But at the same time, passing data via intent could take just as long making the benefits marginal

Insight appreciated

Was it helpful?

Solution

In my experience the onCreate() of your new activity is called almost instantly from when you call startActivity(). The new activity doesn't show up right way because it has to take time to render your layout.

You could play around with timings yourself by using the Log.d() function. Something like Log.d(TAG, "This happend at: " + System.currentTimeMillis()); at different points in your code to see when things happen. Watch the LogCat while your apps runs and you can decide for your self which way is better.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top