Example usage for android.os Handler Handler

List of usage examples for android.os Handler Handler

Introduction

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

Prototype

public Handler() 

Source Link

Document

Default constructor associates this handler with the Looper for the current thread.

Usage

From source file:com.kircherelectronics.accelerationexplorer.activity.NoiseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.layout_noise);

    textViewXAxis = (TextView) findViewById(R.id.value_x_axis);
    textViewYAxis = (TextView) findViewById(R.id.value_y_axis);
    textViewZAxis = (TextView) findViewById(R.id.value_z_axis);

    XYPlot noiseLevelsPlot = (XYPlot) findViewById(R.id.plot_noise);
    noiseLevelsPlot.setTitle("Noise");

    barPlot = new DynamicBarPlot(noiseLevelsPlot, "Sensor Noise", this);

    sensorManager = (SensorManager) this.getSystemService(Context.SENSOR_SERVICE);

    lpf = new LowPassFilterSmoothing();
    meanFilter = new MeanFilterSmoothing();
    medianFilter = new MedianFilterSmoothing();

    initStatistics();//from w  w w  .  j  a v a2 s .  co m

    handler = new Handler();

    runable = new Runnable() {
        @Override
        public void run() {
            handler.postDelayed(this, 100);

            updateBarPlot();
            updateAccelerationText();
        }
    };
}

From source file:net.evecom.android.log.DailyLogListActivity.java

/**
 * /*from  www.  j a va 2 s.  c  o m*/
 */
private void getXmlAndSetList() {
    Runnable runnable = new Runnable() {
        public void run() {
            String strUrl = HttpUtil.BASE_URL + "teventAndroid/lookDailyLogAndroid?" + "areaId="
                    + ShareUtil.getString(getApplicationContext(), "SESSION", "AREAID", "0")
            // + "&personid=" +
            // ShareUtil.getString(getApplicationContext(),
            // "SESSION", "EMPID", "1")
            // + "&personname=" +
            // ShareUtil.getString(getApplicationContext(),
            // "SESSION", "EMPNAME", "")
                    + "&start=" + 1 + "&end=" + pageSize;
            try {
                sss = connServerForResult(strUrl);
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            String listdailyLogPerson = sss;
            try {
                dailyLogPerson = getPersons(listdailyLogPerson);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            handler.sendMessage(handler.obtainMessage(0, dailyLogPerson));
        }
    };
    try {
        // 
        new Thread(runnable).start();
        // handler
        handler = new Handler() {
            public void handleMessage(Message msg) {
                if (msg.what == 0) {
                    BinderListData(dailyLogPerson);
                }

            }
        };

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

From source file:com.echopf.ECHODataObject.java

/**
 * Does Fetch data from the remote server in a background thread.
 * /*w  w w  .  j av  a 2  s  .c  om*/
 * @param sync if set TRUE, then the main (UI) thread is waited for complete the fetching in a background thread. 
 *              (a synchronous communication)
 * @param callback invoked after the fetching is completed
 * @throws ECHOException 
 */
protected void doFetch(final boolean sync, final FetchCallback<S> callback) throws ECHOException {
    final Handler handler = new Handler();

    // Get ready a background thread
    ExecutorService executor = Executors.newSingleThreadExecutor();
    Callable<Object> communictor = new Callable<Object>() {

        @Override
        public Object call() throws ECHOException {

            ECHOException exception = null;
            JSONObject data = null;

            try {

                synchronized (lock) {
                    data = ECHOQuery.getRequest(getRequestURLPath());
                    copyData(data);
                }

            } catch (ECHOException e) {
                exception = e;
            } catch (Exception e) {
                exception = new ECHOException(e);
            }

            if (sync == false) {

                // Execute a callback method in the main (UI) thread.
                if (callback != null) {
                    final ECHOException fException = exception;

                    handler.post(new Runnable() {
                        @Override
                        @SuppressWarnings("unchecked")
                        public void run() {
                            callback.done((S) ECHODataObject.this, fException);
                        }
                    });
                }

            } else {

                if (exception != null)
                    throw exception;

            }

            return null;
        }
    };

    Future<Object> future = executor.submit(communictor);

    if (sync) {
        try {
            future.get();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt(); // ignore/reset
        } catch (ExecutionException e) {
            Throwable e2 = e.getCause();

            if (e2 instanceof ECHOException) {
                throw (ECHOException) e2;
            }

            throw new RuntimeException(e2);
        }
    }
}

From source file:com.uproot.trackme.LocationActivity.java

/**
 * This sample demonstrates how to incorporate location based services in your
 * app and process location updates. The app also shows how to convert
 * lat/long coordinates to human-readable addresses.
 */// w ww.  j a v  a  2s  . co  m
@SuppressLint({ "NewApi", "HandlerLeak" })
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // clearDB();
    initDatabase();

    Button btn1 = (Button) findViewById(R.id.btn1);
    btn1.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            finish();
        }
    });

    if (savedInstanceState != null) {
        mUseFine = savedInstanceState.getBoolean(KEY_FINE);
        mUseBoth = savedInstanceState.getBoolean(KEY_BOTH);
    } else {
        mUseFine = false;
        mUseBoth = false;
    }
    mUseFine = false;
    mUseBoth = true;
    mLatLng = (TextView) findViewById(R.id.latlng);
    mAddress = (TextView) findViewById(R.id.address);

    // The isPresent() helper method is only available on Gingerbread or
    // above.
    mGeocoderAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && Geocoder.isPresent();

    // Handler for updating text fields on the UI like the lat/long and
    // address.
    mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case UPDATE_ADDRESS:
                mAddress.setText((String) msg.obj);
                break;
            case UPDATE_LATLNG:
                mLatLng.setText((String) msg.obj);
                break;
            }
        }
    };
    // Get a reference to the LocationManager object.
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    setup();

    myTimer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            getLocs();
        }
    }, 0, setF * 1000);

}

From source file:com.app.jdy.ui.CallBackPasswordActivity.java

/**
 * //from  w  ww . j  av a  2 s  . c  o  m
 * @author Owater
 * @createtime 2015-1-13 ?6:04:53
 * @Decription ??
 * 
 */
public void initView() {
    mBackImg = (ImageView) findViewById(R.id.back_img);
    mBackImg.setVisibility(View.VISIBLE);
    title = (TextView) findViewById(R.id.title_tv);
    title.setText("?");
    back_password_username = (EditText) findViewById(R.id.back_password_username);
    get_back_password_code = (Button) findViewById(R.id.get_back_password_code);
    back_password_code = (EditText) findViewById(R.id.back_password_code);
    set_back_password_code = (Button) findViewById(R.id.set_back_password_code);
    get_code_linearlayout = (LinearLayout) findViewById(R.id.get_code_linearlayout);
    set_code_linearlayout = (LinearLayout) findViewById(R.id.set_code_linearlayout);
    find_password_ok_linearlayout = (LinearLayout) findViewById(R.id.find_password_ok_linearlayout);
    back_new_password = (EditText) findViewById(R.id.back_new_password);
    back_new_repassword = (EditText) findViewById(R.id.back_new_repassword);
    find_password_ok = (Button) findViewById(R.id.find_password_ok);
    back_login = (TextView) findViewById(R.id.back_login);
    pd = new ProgressDialog(this);
    handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case 0:
                Toast.makeText(CallBackPasswordActivity.this, Constants.NO_INTENT_TIPS, Toast.LENGTH_LONG)
                        .show();
                break;
            case 1:
                Toast.makeText(CallBackPasswordActivity.this, "????,?",
                        Toast.LENGTH_LONG).show();
                get_code_linearlayout.setVisibility(View.GONE);
                set_code_linearlayout.setVisibility(View.VISIBLE);
                break;
            case 2:
                try {
                    Toast.makeText(CallBackPasswordActivity.this, jsonObject.getString("msg").toString(),
                            Toast.LENGTH_SHORT).show();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                break;
            case 3:
                set_code_linearlayout.setVisibility(View.GONE);
                find_password_ok_linearlayout.setVisibility(View.VISIBLE);
                break;
            case 4:
                try {
                    Toast.makeText(CallBackPasswordActivity.this, jsonObject.getString("msg").toString(),
                            Toast.LENGTH_LONG).show();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                break;
            case 5:
                try {
                    Toast.makeText(CallBackPasswordActivity.this, jsonObject.getString("msg").toString(),
                            Toast.LENGTH_LONG).show();
                } catch (JSONException e1) {
                    e1.printStackTrace();
                }
                startActivity(new Intent(CallBackPasswordActivity.this, LoginActivity.class));
                finish();
                break;
            case 6:
                try {
                    Toast.makeText(CallBackPasswordActivity.this, jsonObject.getString("msg").toString(),
                            Toast.LENGTH_LONG).show();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                break;
            default:
                break;
            }
        }
    };
}

From source file:com.samknows.measurement.activity.SamKnowsTestViewerActivity.java

/** Called when the activity is first created. */
@Override//  w w w.  j a  v  a 2  s .  co  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    cxt = this;

    Bundle b = getIntent().getExtras();
    int testID = -1;

    if (b != null) {
        testID = b.getInt("testID");
    }

    storage = CachingStorage.getInstance();
    config = storage.loadScheduleConfig();
    if (config == null) {
        config = new ScheduleConfig();
    }
    testList = config.manual_tests;
    array_spinner = new String[testList.size() + 1];
    array_spinner_int = new int[testList.size() + 1];

    this.setTitle(R.string.running_test);

    // choose which test to run
    setContentView(R.layout.individual_stat_test);

    Util.initializeFonts(this);
    Util.overrideFonts(this, findViewById(android.R.id.content));
    try {

        handler = new Handler() {

            @Override
            public void handleMessage(Message msg) {
                TextView tv = null;

                JSONObject message_json;
                message_json = (JSONObject) msg.obj;
                String value;
                int success;
                int testname;
                int status_complete;
                int metric;

                try {

                    String type = message_json.getString(TestResult.JSON_TYPE_ID);

                    if (type == "completed") {

                        result = 1;
                        SamKnowsTestViewerActivity.this.finish();
                        overridePendingTransition(0, 0);
                    }

                    if (type == "test") {
                        testname = message_json.getInt(TestResult.JSON_TESTNUMBER);
                        status_complete = message_json.getInt(TestResult.JSON_STATUS_COMPLETE);
                        value = message_json.getString(TestResult.JSON_HRRESULT);
                        if (status_complete == 100 && message_json.has(TestResult.JSON_SUCCESS)) {

                            success = message_json.getInt(TestResult.JSON_SUCCESS);
                            if (success == 0) {
                                value = getString(R.string.failed);
                            }
                        }

                        switch (testname) {
                        // active metrics
                        case TestResult.DOWNLOAD_TEST_ID:
                            pw = (ProgressWheel) findViewById(R.id.ProgressWheel1);
                            tv = (TextView) findViewById(R.id.download_result);
                            pw.setProgress((int) (status_complete * 3.6));
                            pw.setContentDescription("Status " + status_complete + "%");
                            if (status_complete == 100) {
                                pw.setVisibility(View.GONE);
                                tv.setText(value);
                                tv.setContentDescription(getString(R.string.download) + " " + value);
                                tv.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
                            } else {
                                pw.setVisibility(View.VISIBLE);
                                tv.setText("");
                            }
                            break;
                        case TestResult.UPLOAD_TEST_ID:
                            pw = (ProgressWheel) findViewById(R.id.ProgressWheel2);
                            tv = (TextView) findViewById(R.id.upload_result);
                            pw.setProgress((int) (status_complete * 3.6));
                            pw.setContentDescription("Status " + status_complete + "%");
                            if (status_complete == 100) {
                                pw.setVisibility(View.GONE);

                                tv.setText(value);
                                tv.setContentDescription(getString(R.string.upload) + " " + value);
                                tv.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
                            } else {
                                pw.setVisibility(View.VISIBLE);
                                tv.setText("");
                            }
                            break;
                        case TestResult.PACKETLOSS_TEST_ID:
                            pw = (ProgressWheel) findViewById(R.id.ProgressWheel3);
                            tv = (TextView) findViewById(R.id.packetloss_result);
                            pw.setProgress((int) (status_complete * 3.6));
                            pw.setContentDescription("Status " + status_complete + "%");
                            if (status_complete == 100) {
                                pw.setVisibility(View.GONE);
                                tv.setText(value);
                                tv.setContentDescription(getString(R.string.packet_loss) + " " + value);
                                tv.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
                            } else {
                                pw.setVisibility(View.VISIBLE);
                                tv.setText("");
                            }
                            break;
                        case TestResult.LATENCY_TEST_ID:
                            pw = (ProgressWheel) findViewById(R.id.ProgressWheel4);
                            tv = (TextView) findViewById(R.id.latency_result);
                            pw.setProgress((int) (status_complete * 3.6));
                            pw.setContentDescription("Status " + status_complete + "%");
                            if (status_complete == 100) {
                                pw.setVisibility(View.GONE);
                                tv.setText(value);
                                tv.setContentDescription(getString(R.string.latency) + " " + value);
                                tv.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
                            } else {
                                pw.setVisibility(View.VISIBLE);
                                tv.setText("");
                            }
                            break;
                        case TestResult.JITTER_TEST_ID:
                            pw = (ProgressWheel) findViewById(R.id.ProgressWheel5);
                            tv = (TextView) findViewById(R.id.jitter_result);
                            pw.setProgress((int) (status_complete * 3.6));
                            pw.setContentDescription("Status " + status_complete + "%");
                            if (status_complete == 100) {
                                pw.setVisibility(View.GONE);
                                tv.setText(value);
                                tv.setContentDescription(getString(R.string.jitter) + " " + value);
                                tv.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
                            } else {
                                pw.setVisibility(View.VISIBLE);
                                tv.setText("");
                            }
                            break;

                        }
                    }

                    if (type == "passivemetric") {
                        metric = message_json.getInt("metric");
                        value = message_json.getString("value");

                        switch (metric) {

                        // passive metrics
                        case 1:
                            tv = (TextView) findViewById(R.id.passivemetric1);
                            tv.setText(value);
                            break;

                        case 2:
                            tv = (TextView) findViewById(R.id.passivemetric2);
                            tv.setText(value);
                            break;

                        case 3:
                            tv = (TextView) findViewById(R.id.passivemetric3);
                            tv.setText(value);
                            break;

                        case 4:
                            tv = (TextView) findViewById(R.id.passivemetric4);
                            tv.setText(value);
                            break;

                        case 5:
                            tv = (TextView) findViewById(R.id.passivemetric5);
                            tv.setText(value);
                            break;

                        case 6:
                            tv = (TextView) findViewById(R.id.passivemetric6);
                            tv.setText(value);
                            break;

                        case 7:
                            tv = (TextView) findViewById(R.id.passivemetric7);
                            tv.setText(value);
                            break;

                        case 8:
                            tv = (TextView) findViewById(R.id.passivemetric8);
                            tv.setText(value);
                            break;

                        case 9:
                            tv = (TextView) findViewById(R.id.passivemetric9);
                            tv.setText(value);
                            break;

                        case 10:
                            tv = (TextView) findViewById(R.id.passivemetric10);
                            tv.setText(value);
                            break;

                        case 11:
                            tv = (TextView) findViewById(R.id.passivemetric11);
                            tv.setText(value);
                            break;
                        case 12:
                            tv = (TextView) findViewById(R.id.passivemetric12);
                            tv.setText(value);
                            break;
                        case 13:
                            tv = (TextView) findViewById(R.id.passivemetric13);
                            tv.setText(value);
                            break;
                        case 14:
                            tv = (TextView) findViewById(R.id.passivemetric14);
                            tv.setText(value);
                            break;
                        case 15:
                            tv = (TextView) findViewById(R.id.passivemetric15);
                            tv.setText(value);
                            break;
                        case 16:
                            tv = (TextView) findViewById(R.id.passivemetric16);
                            tv.setText(value);
                            break;
                        case 17:
                            tv = (TextView) findViewById(R.id.passivemetric17);
                            tv.setText(value);
                            break;
                        case 18:
                            tv = (TextView) findViewById(R.id.passivemetric18);
                            tv.setText(value);
                            break;
                        case 19:
                            tv = (TextView) findViewById(R.id.passivemetric19);
                            tv.setText(value);
                            break;
                        case 20:
                            tv = (TextView) findViewById(R.id.passivemetric20);
                            tv.setText(value);
                            break;
                        case 21:
                            tv = (TextView) findViewById(R.id.passivemetric21);
                            tv.setText(value);
                            break;
                        case 22:
                            tv = (TextView) findViewById(R.id.passivemetric22);
                            tv.setText(value);
                            break;
                        case 23:
                            tv = (TextView) findViewById(R.id.passivemetric23);
                            tv.setText(value);
                            break;
                        case 24:
                            tv = (TextView) findViewById(R.id.passivemetric24);
                            tv.setText(value);
                            break;
                        case 25:
                            tv = (TextView) findViewById(R.id.passivemetric25);
                            tv.setText(value);
                            break;
                        case 26:
                            tv = (TextView) findViewById(R.id.passivemetric26);
                            tv.setText(value);
                            break;
                        case 27:
                            tv = (TextView) findViewById(R.id.passivemetric27);
                            tv.setText(value);
                            break;
                        case 28:
                            tv = (TextView) findViewById(R.id.passivemetric28);
                            tv.setText(value);
                            break;
                        case 29:
                            tv = (TextView) findViewById(R.id.passivemetric29);
                            tv.setText(value);
                            break;
                        case 30:
                            tv = (TextView) findViewById(R.id.passivemetric30);
                            tv.setText(value);
                            break;
                        case 31:
                            tv = (TextView) findViewById(R.id.passivemetric31);
                            tv.setText(value);
                            break;
                        case 32:
                            tv = (TextView) findViewById(R.id.passivemetric32);
                            tv.setText(value);
                            break;
                        default:
                            //

                        }
                        if (!value.equals("") && tv != null) {

                            TableLayout tl1 = (TableLayout) findViewById(R.id.passive_metrics_status);
                            tl1.setVisibility(View.GONE);
                            TableLayout tl = (TableLayout) tv.getParent().getParent();
                            tl.setVisibility(View.VISIBLE);
                        }

                        if (value.equals("") && tv != null) {
                            TableLayout tl = (TableLayout) tv.getParent().getParent();
                            tl.setVisibility(View.GONE);
                        }

                    }

                } catch (JSONException e) {
                    Logger.e(this, e.getMessage());
                }
            }
        };

        launchTest(testID);
    } catch (Throwable t) {
        Logger.e(this, "handler or test failure", t);
    }
}

From source file:com.cranberrygame.cordova.plugin.navigationbar.NavigationBar.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void _setUp(boolean autoHideNavigationBar) {
    if (autoHideNavigationBar) {
        Activity activity = cordova.getActivity();
        //http://stackoverflow.com/questions/21164836/immersive-mode-navigation-becomes-sticky-after-volume-press-or-minimise-restore
        //http://www.youtube.com/watch?v=Xw9TIS_JsPM      
        //https://developer.android.com/training/system-ui/status.html
        activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION//
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                //| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                //| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

        final CordovaInterface cordova_final = cordova;
        //http://stackoverflow.com/questions/11762306/listen-for-first-touchevent-when-using-system-ui-flag-hide-navigation
        //http://stackoverflow.com/questions/15103339/android-full-screen-modeics-first-touch-shows-the-navigation-bar
        //http://developer.android.com/reference/android/view/View.OnSystemUiVisibilityChangeListener.html   
        //webView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener(){//cordova5 build error
        getView(webView).setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {//fixed cordova5 build error
            @Override/*from   w  w  w  .jav  a2  s  .com*/
            public void onSystemUiVisibilityChange(int vis) {
                if (vis == 0) {
                    //http://stackoverflow.com/questions/3072173/how-to-call-a-method-after-a-delay-in-android
                    Handler handler = new Handler();
                    handler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            Activity activity = cordova_final.getActivity();
                            activity.getWindow().getDecorView()
                                    .setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION//
                                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            //| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            //| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
                        }
                    }, 3000);//after ms                
                }
            }
        });
    }
}

From source file:com.zia.freshdocs.widget.adapter.CMISAdapter.java

/**
 * Handles connecting to the host, get host info such as version and then
 * displays the Company Home contents.//from ww  w.  jav a  2 s  .  co  m
 */
public void home() {
    startProgressDlg(true);

    mDlThread = new ChildDownloadThread(new Handler() {
        public void handleMessage(Message msg) {
            // Save reference to current entry
            mStack.clear();

            NodeRef[] companyHome = (NodeRef[]) mDlThread.getResult();

            if (companyHome != null) {
                dismissProgressDlg();

                // Get Company Home children
                mCurrentState = new Pair<String, NodeRef[]>("", companyHome);
                populateList(companyHome);
            } else {
                CMISApplication app = (CMISApplication) getContext().getApplicationContext();
                app.handleNetworkStatus();
            }
        }
    }, new Downloadable() {
        public Object execute() {
            return mCmis.getCompanyHome();
        }
    });
    mDlThread.start();
}

From source file:foam.zizim.android.BoskoiService.java

@Override
public void onCreate() {
    super.onCreate();
    queue = new QueueThread("ushahidi");
    mHandler = new Handler();

    if (AutoFetch) {
        // Log.i("Service ","Service is checked to start.");
        mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        mHandler.postDelayed(mUpdateTimeTask, (1000 * 60 * AutoUpdateDelay));

    } else {/*from ww  w .  ja  v  a  2s  .  c om*/
        // Log.i("Service ","Service is unchecked.");
    }

    final Thread tr = new Thread() {
        @Override
        public void run() {
            while (true) {
                queue.GetQueueItem().start();
            }
        }
    };
    tr.start();
}

From source file:net.networksaremadeofstring.rhybudd.ZenossPoller.java

@Override
public void onCreate() {
    settings = PreferenceManager.getDefaultSharedPreferences(this);
    //Log.i("ServiceThread","Service Starting");

    BugSenseHandler.initAndStartSession(ZenossPoller.this, "44a76a8c");

    String ns = Context.NOTIFICATION_SERVICE;
    mNM = (NotificationManager) getSystemService(ns);

    PrepAPI(true, false);/*from   ww w . j a v  a2  s .  co  m*/

    eventsHandler = new Handler() {
        public void handleMessage(Message msg) {
            if (msg.what == 1) {
                //onlyAlertOnProd = settings.getBoolean("onlyProductionAlerts", true);
                EventDetails.clear();

                Boolean alertsEnabled = settings.getBoolean("AllowBackgroundService", true);
                if (null != listOfZenossEvents && listOfZenossEvents.size() > 0) {
                    try {
                        EventCount = 0;
                        for (ZenossEvent event : listOfZenossEvents) {
                            if (alertsEnabled && event.isNew()
                                    && ZenossAPI.CheckIfNotify(event.getProdState(), event.getDevice(),
                                            getApplicationContext(),
                                            settings.getBoolean("onlyProductionAlerts", true))) {
                                EventDetails.add(event.getDevice() + ": " + event.getSummary());
                                EventCount++;
                            }
                        }

                        if (EventCount > 0) {
                            Notifications.SendPollNotification(EventCount, EventDetails,
                                    getApplicationContext());
                        }
                    } catch (Exception e) {
                        BugSenseHandler.sendExceptionMessage("ZenossPoller", "eventsHandler", e);
                        e.printStackTrace();
                    }
                } else {
                    //This should never happen but also people should stop using the Poller and move to Rhybudd Push
                }

                if (alertsEnabled) {
                    Notifications.SendStickyNotification(getApplicationContext());
                } else {
                    ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE))
                            .cancel(Notifications.NOTIFICATION_POLLED_STICKY);
                }
            } else if (msg.what == 999) {
                //TODO All manner of bad happened
            }

            EventsRefreshInProgress = false;
        }
    };
}