Example usage for android.os Handler post

List of usage examples for android.os Handler post

Introduction

In this page you can find the example usage for android.os Handler post.

Prototype

public final boolean post(Runnable r) 

Source Link

Document

Causes the Runnable r to be added to the message queue.

Usage

From source file:com.android.managedprovisioning.ProfileOwnerProvisioningActivity.java

@Override
protected void onResume() {
    super.onResume();

    // Setup broadcast receiver for feedback from service.
    mServiceMessageReceiver = new ServiceMessageReceiver();
    IntentFilter filter = new IntentFilter();
    filter.addAction(ProfileOwnerProvisioningService.ACTION_PROVISIONING_SUCCESS);
    filter.addAction(ProfileOwnerProvisioningService.ACTION_PROVISIONING_ERROR);
    filter.addAction(ProfileOwnerProvisioningService.ACTION_PROVISIONING_CANCELLED);
    LocalBroadcastManager.getInstance(this).registerReceiver(mServiceMessageReceiver, filter);

    // Start service async to make sure the UI is loaded first.
    final Handler handler = new Handler(getMainLooper());
    handler.post(new Runnable() {
        @Override//from www  .j av a 2  s.com
        public void run() {
            Intent intent = new Intent(ProfileOwnerProvisioningActivity.this,
                    ProfileOwnerProvisioningService.class);
            intent.putExtras(getIntent());
            startService(intent);
        }
    });
}

From source file:com.facebook.AccessTokenManager.java

void refreshCurrentAccessToken() {
    if (Looper.getMainLooper().equals(Looper.myLooper())) {
        refreshCurrentAccessTokenImpl();
    } else {/* w  w  w.  j  a  v  a 2 s .  com*/
        Handler mainHandler = new Handler(Looper.getMainLooper());
        mainHandler.post(new Runnable() {
            @Override
            public void run() {
                refreshCurrentAccessTokenImpl();
            }
        });
    }
}

From source file:com.appnexus.opensdk.mediatednativead.InMobiNativeAdResponse.java

@Override
public void destroy() {
    Handler handler = new Handler(Looper.getMainLooper());
    handler.removeCallbacks(runnable);//w ww . j  a v a2 s .c  o  m
    handler.post(runnable);
}

From source file:com.phonegap.plugins.speech.XSpeechRecognizer.java

/**
 * Fire an intent to start the speech recognition activity.
 *
 * @param args Argument array with the following string args: [req code][number of matches]
 *///  w w  w .  j  a  v  a2  s  . co m
private void startSpeechRecognitionActivity(JSONArray args) {

    int maxMatches = 0;
    String language = Locale.getDefault().toString();

    try {
        if (args.length() > 0) {
            // Maximum number of matches, 0 means the recognizer decides
            String temp = args.getString(0);
            maxMatches = Integer.parseInt(temp);
        }
        if (args.length() > 1) {
            // Language
            language = args.getString(1);
        }
    } catch (Exception e) {
        Log.e(TAG, String.format("startSpeechRecognitionActivity exception: %s", e.toString()));
    }

    // Create the intent and set parameters
    final Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    // intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test");
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);

    if (maxMatches > 0)
        intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxMatches);

    Handler loopHandler = new Handler(Looper.getMainLooper());
    loopHandler.post(new Runnable() {

        @Override
        public void run() {
            recognizer.startListening(intent);
        }

    });
}

From source file:com.licubeclub.zionhs.Notices_Parents.java

private void networkTask() {
    final Handler mHandler = new Handler();
    new Thread() {

        public void run() {

            mHandler.post(new Runnable() {

                public void run() {
                    SRL.setRefreshing(true);
                }/*from   w  w w  .  j  a v  a2  s. c  o  m*/
            });

            //Task

            //Notices URL
            try {
                titlearray = new ArrayList<String>();
                titleherfarray = new ArrayList<String>();
                authorarray = new ArrayList<String>();
                datearray = new ArrayList<String>();
                Document doc = Jsoup.connect(
                        "http://www.zion.hs.kr/main.php?menugrp=110100&master=bbs&act=list&master_sid=59")
                        .get();
                Elements rawdata = doc.select(".listbody a"); //Get contents from tags,"a" which are in the class,"listbody"
                Elements rawauthordata = doc.select("td:eq(3)"); //? ?  - 3 td ? 
                Elements rawdatedata = doc.select("td:eq(4)"); // ?  - 4 td ? 

                String titlestring = rawdata.toString();
                Log.i("Notices", "Parsed Strings" + titlestring);

                for (Element el : rawdata) {
                    String titlherfedata = el.attr("href");
                    String titledata = el.attr("title");
                    titleherfarray.add("http://www.zion.hs.kr/" + titlherfedata); // add value to ArrayList
                    titlearray.add(titledata); // add value to ArrayList
                }
                Log.i("Notices", "Parsed Link Array Strings" + titleherfarray);
                Log.i("Notices", "Parsed Array Strings" + titlearray);

                for (Element el : rawauthordata) {
                    String authordata = el.text();
                    Log.d("Author", el.text());
                    authorarray.add(authordata);
                }
                for (Element el : rawdatedata) {
                    String datedata = el.text();
                    Log.d("Date", el.text());
                    datearray.add(datedata);
                }

            } catch (IOException e) {
                e.printStackTrace();

            }

            mHandler.post(new Runnable() {
                public void run() {
                    //UI Task
                    adapter = new PostListAdapter(Notices_Parents.this, titlearray, datearray, authorarray);
                    listview.setAdapter(adapter);
                    listview.setOnItemClickListener(GoToWebPage);
                    handler.sendEmptyMessage(0);
                    SRL.setRefreshing(false);

                    Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.noti_parents_info),
                            Toast.LENGTH_LONG);
                    toast.setGravity(Gravity.TOP, 0, 0);
                    toast.show();
                }
            });

        }
    }.start();

}

From source file:com.facebook.AccessTokenManager.java

void refreshCurrentAccessToken(final AccessToken.AccessTokenRefreshCallback callback) {
    if (Looper.getMainLooper().equals(Looper.myLooper())) {
        refreshCurrentAccessTokenImpl(callback);
    } else {//  ww  w.j av  a  2  s.c  o  m
        Handler mainHandler = new Handler(Looper.getMainLooper());
        mainHandler.post(new Runnable() {
            @Override
            public void run() {
                refreshCurrentAccessTokenImpl(callback);
            }
        });
    }
}

From source file:com.kytse.aria2remote.DownloadListFragment.java

@Override
public void onAria2ListItemChanged(Aria2.ListType type, final int position) {
    if (type == mType) {
        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            @Override/*from w  w w.j a v a 2s.c om*/
            public void run() {
                mAdapter.notifyItemChanged(position);
            }
        });
    }
}

From source file:com.kytse.aria2remote.DownloadListFragment.java

@Override
public void onAria2ListItemInserted(Aria2.ListType type, final int position) {
    if (type == mType) {
        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            @Override/*  w w w  .  j a  va2  s.  c om*/
            public void run() {
                mAdapter.notifyItemInserted(position);
            }
        });
    }
}

From source file:com.kytse.aria2remote.DownloadListFragment.java

@Override
public void onAria2ListItemRemoved(Aria2.ListType type, final int position) {
    if (type == mType) {
        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            @Override//from w w  w.j a  v  a2  s  .com
            public void run() {
                mAdapter.notifyItemRemoved(position);
            }
        });
    }
}

From source file:com.kytse.aria2remote.DownloadListFragment.java

@Override
public void onAria2ListItemMoved(Aria2.ListType type, final int oldPosition, final int newPosition) {
    if (type == mType) {
        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            @Override/*from  www .j a v  a  2s . c  o m*/
            public void run() {
                mAdapter.notifyItemMoved(oldPosition, newPosition);
            }
        });
    }
}