編輯:關於Android編程
public class PushServices extends UmengBaseIntentService { private PushAgent mPushAgent; private ScheduledExecutorService service; private ScheduledFuture scheduledFuture; private int i = 1; private Handler handler = new Handler() { public void handleMessage(android.os.Message msg) { Toast.makeText(getApplicationContext(), "定時:"+msg.what, Toast.LENGTH_SHORT).show(); }; }; @Override public void onCreate() { // TODO Auto-generated method stub super.onCreate(); try { timeTask(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * * @Title: timeTask * @Description: TODO 定時更新任務,一集定時上傳 * @return void */ public void timeTask() throws InterruptedException, ExecutionException { // TODO Auto-generated method stub if (service == null) { service = Executors.newScheduledThreadPool(1); } if (scheduledFuture == null) { scheduledFuture = service.scheduleAtFixedRate(new UploadData(), 0, 5, TimeUnit.SECONDS); } } @Override protected void onMessage(Context context, Intent intent) { // TODO Auto-generated method stub super.onMessage(context, intent); try { String message = intent.getStringExtra(BaseConstants.MESSAGE_BODY); if (StringUtils.isEmpty(message)) { return; } UMessage msg = new UMessage(new JSONObject(message)); if (msg != null) { mPushAgent = PushAgent.getInstance(context); UmengMessageHandler messageHandler = new UmengMessageHandler(); messageHandler.dealWithNotificationMessage(context, msg); UmengNotificationClickHandler notificationClickHandler = new UmengNotificationClickHandler(); mPushAgent.setMessageHandler(messageHandler); mPushAgent .setNotificationClickHandler(notificationClickHandler); UTrack.getInstance(context).trackMsgClick(msg); } } catch (Exception e) { } } @Override public void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); if (scheduledFuture != null) { scheduledFuture.cancel(true); scheduledFuture = null; } } // 上傳任務 public class UploadData implements Runnable { @Override public void run() { // TODO Auto-generated method stub i++; Message message=Message.obtain(); message.what=i; handler.sendMessage(message); } } }
[Android][Memory Leak] InputMethodManager內存洩露現象及解決 現象: 在特定的機型天語k_touch_v9機型上
本篇主要是對 google推出的性能優化典范 進行一個通篇的整理… 主要在於一些具體的優化技巧、至於 60fps、掉幀、gc、內存抖動、阈值…
Android系統中的ContextMenu(上下文菜單)類似於PC中的右鍵彈出菜單,當一個視圖注冊到一個上下文菜單時,執行一個在該對象上的“長按”動作,將出
前幾篇文章講過listview的自定義下拉刷新上拉加載,最近一直考慮再來個RecyclerView的下拉刷新和上拉加載,畢竟RecyclerView使用的越來越多了,扒了