-1

I have 2 methods in onCreate which I need to run one after the other ie...the second method will start once the first method is complete irrespective of how much time it takes.Please help me.

new Handler().postDelayed(new Runnable() {

        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */

        @Override
        public void run() {
            // This method will be executed once the timer is over
            // Start your app main activity

               populateList();

            // close this activity
            //finish();
        }
    }, 20000);getContactList();

populateList() method

** public void populateList() {
Log.i("Populate List","Entered");

    Toast.makeText(this,String.valueOf(Common.selectedContactNos.size()),Toast.LENGTH_LONG).show();
   displayRecyclerAdapter = new DisplayRecyclerAdapter(DisplayContacts.this);
   LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager(this);
    recyclerView_contacts.setAdapter(displayRecyclerAdapter);
   recyclerView_contacts.setLayoutManager(mLinearLayoutManager);
   displayRecyclerAdapter.notifyDataSetChanged();
}**
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
user8601021
  • 219
  • 3
  • 18

2 Answers2

1

just use AsyncTask

call TaskOne class like- new TaskOne().execute();

private class TaskOne extends AsyncTask<Void,Void,Void>
{

    @Override
    protected Void doInBackground(Void... params) {
        getContactList(); 
        return null;
    }

    @Override
    protected void onPostExecute(Void aVoid) {
        super.onPostExecute(aVoid);
        populateList();


    }
}
Ankit
  • 1,068
  • 6
  • 10
0

Call both method inside run method with the sequence you want. Replace your code with below code

 new Handler().postDelayed(new Runnable() {

    /*
     * Showing splash screen with a timer. This will be useful when you
     * want to show case your app logo / company
     */

        @Override
        public void run() {
            // This method will be executed once the timer is over
            // Start your app main activity

            populateList();
            getContactList();
            // close this activity
            //finish();
        }
    }, 20000);
Abdul Waheed
  • 4,540
  • 6
  • 35
  • 58