how to make fast my android app how to make fast my android app json json

how to make fast my android app


try to use thread pool executorrefer this and this for learn and understand. by using thread pool executor you can run multiple tasks at the same time or we can say parallel.

private void startAsyncTaskInParallel(MyAsyncTask task) {    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);    else        task.execute();}


Can you get around this by putting the APIx() calls into a runnable task?

class MyClass {    public boolean ready = false;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        handler = new Handler();        final Runnable r = new Runnable() {            public void run() {                API1();                API2();                API3();                API4();                ready = true;            }        };        handler.postDelayed(r, 100);    }}


Is your FetchData class a runnable of some kind? If it is an asynctask (looks like), the problem may lie in the listener's placement. If you call it in any other callback than doInBackground, the listener is going to be executed into the UI thread. Even assuming all your api calls are asynchronous, a bottleneck will be created.Another cause of performance loss is having too many tasks waiting to execute. A good way to avoid such a problem is by using a dedicated ThreadPoolExecutor when dealing with runnables, and using the executeOnExecutor(AsyncTask.ThreadPoolExecutor) method in the asynctasks.

If your calls are not asynchronous, then you must make them asynchronous. This means, executing all the non-ui related code in a separated, parallel thread, so the UI does not get blocked while you make all the calls. take a look at this

(I'm the dev), specifically, at the doInBackground method (line 994). As you can see, all the Rest call code, serialization code, and async callbacks are executed in this phase. The onPostExecute phase only executes the synchronous listeners (UI - related, basically) in order to reduce the workload of the UI thread. You can do exactly the same in your FetchData class.