看图, 只要点击取消或是下载完毕 通知才会消失!

    

代码是大部分是借用别人的,再自己修改,达到自己所需要的效果

xml文件

update.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:background="@drawable/newlogin_bg"
  6. android:orientation="vertical" >
  7. <TextView
  8. android:layout_width="fill_parent"
  9. android:layout_height="wrap_content"
  10. android:layout_marginLeft="4dp"
  11. android:layout_marginTop="10dp"
  12. android:text="正在下载..."
  13. android:textColor="#000" />
  14. <TextView
  15. android:id="@+id/currentPos"
  16. android:layout_width="fill_parent"
  17. android:layout_height="wrap_content"
  18. android:layout_marginBottom="6dp"
  19. android:layout_marginLeft="4dp"
  20. android:layout_marginTop="10dp"
  21. android:textColor="#000" />
  22. <ProgressBar
  23. android:id="@+id/progressbar1"
  24. style="?android:attr/progressBarStyleHorizontal"
  25. android:layout_width="fill_parent"
  26. android:layout_height="wrap_content"
  27. android:layout_margin="4dp"
  28. android:max="100"
  29. android:progress="0" />
  30. <Button
  31. android:id="@+id/cancel"
  32. android:layout_width="wrap_content"
  33. android:layout_height="wrap_content"
  34. android:layout_gravity="center_horizontal"
  35. android:layout_marginTop="10dp"
  36. android:minWidth="200dp"
  37. android:text="取消" />
  38. </LinearLayout>

download_notification_layout.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:layout_gravity="center"
  6. android:orientation="vertical" >
  7. <LinearLayout
  8. android:layout_centerInParent="true"
  9. xmlns:android="http://schemas.android.com/apk/res/android"
  10. android:layout_width="match_parent"
  11. android:layout_height="wrap_content"
  12. android:layout_marginLeft="3dp"
  13. android:layout_marginRight="3dp"
  14. android:orientation="vertical" >
  15. <LinearLayout
  16. xmlns:android="http://schemas.android.com/apk/res/android"
  17. android:layout_width="match_parent"
  18. android:layout_height="wrap_content"
  19. android:orientation="horizontal" >
  20. <ImageView
  21. android:id="@+id/image"
  22. android:layout_width="wrap_content"
  23. android:layout_height="wrap_content"
  24. android:background="@drawable/icon" />
  25. <LinearLayout
  26. xmlns:android="http://schemas.android.com/apk/res/android"
  27. android:layout_width="match_parent"
  28. android:layout_height="wrap_content"
  29. android:layout_marginLeft="3dp"
  30. android:layout_marginRight="3dp"
  31. android:orientation="vertical" >
  32. <LinearLayout
  33. xmlns:android="http://schemas.android.com/apk/res/android"
  34. android:layout_width="match_parent"
  35. android:layout_height="wrap_content"
  36. android:layout_marginTop="2dp"
  37. android:orientation="horizontal" >
  38. <TextView
  39. android:id="@+id/name"
  40. android:layout_width="wrap_content"
  41. android:layout_height="wrap_content"
  42. android:layout_gravity="center_vertical"
  43. android:text="xxxx.apk"
  44. android:textColor="#000" />
  45. <TextView
  46. android:id="@+id/tv_progress"
  47. android:layout_width="wrap_content"
  48. android:layout_height="wrap_content"
  49. android:layout_gravity="center_vertical"
  50. android:gravity="center"
  51. android:minWidth="60dp"
  52. android:textColor="#000" />
  53. </LinearLayout>
  54. <ProgressBar
  55. android:id="@+id/progressbar"
  56. style="?android:attr/progressBarStyleHorizontal"
  57. android:layout_width="fill_parent"
  58. android:layout_height="wrap_content"
  59. android:layout_marginRight="4dp"
  60. android:layout_marginTop="3dp"
  61. android:max="100"
  62. android:progress="0"
  63. android:text="xxxx.apk" />
  64. </LinearLayout>
  65. </LinearLayout>
  66. </LinearLayout>
  67. </RelativeLayout>

MyApp

  1. package com.zeng.update;
  2. import android.app.Application;
  3. public class MyApp extends Application {
  4. private boolean isDownload;
  5. @Override
  6. public void onCreate() {
  7. // TODO Auto-generated method stub
  8. super.onCreate();
  9. isDownload = false;
  10. }
  11. public boolean isDownload() {
  12. return isDownload;
  13. }
  14. public void setDownload(boolean isDownload) {
  15. this.isDownload = isDownload;
  16. }
  17. }

Main

  1. package com.zeng.update;
  2. import android.app.Activity;
  3. import android.app.AlertDialog;
  4. import android.content.DialogInterface;
  5. import android.content.Intent;
  6. import android.content.pm.PackageInfo;
  7. import android.content.pm.PackageManager;
  8. import android.content.pm.PackageManager.NameNotFoundException;
  9. import android.os.Bundle;
  10. import android.view.View;
  11. import android.view.View.OnClickListener;
  12. import android.widget.Button;
  13. public class Main extends Activity {
  14. private Button btn_check;
  15. private MyApp app;
  16. private int currentVersionCode;
  17. @Override
  18. protected void onCreate(Bundle savedInstanceState) {
  19. // TODO Auto-generated method stub
  20. super.onCreate(savedInstanceState);
  21. setContentView(R.layout.main);
  22. app = (MyApp) getApplication();
  23. btn_check = (Button) findViewById(R.id.check);
  24. btn_check.setOnClickListener(new OnClickListener() {
  25. @Override
  26. public void onClick(View v) {
  27. // TODO Auto-generated method stub
  28. PackageManager manager = Main.this.getPackageManager();
  29. try {
  30. PackageInfo info = manager.getPackageInfo(Main.this.getPackageName(), 0);
  31. String appVersion = info.versionName; // 版本名
  32. currentVersionCode = info.versionCode; // 版本号
  33. System.out.println(currentVersionCode + " " + appVersion);
  34. } catch (NameNotFoundException e) {
  35. // TODO Auto-generated catch blockd
  36. e.printStackTrace();
  37. }
  38. //上面是获取manifest中的版本数据,我是使用versionCode
  39. //在从服务器获取到最新版本的versionCode,比较
  40. showUpdateDialog();
  41. }
  42. });
  43. }
  44. private void showUpdateDialog() {
  45. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  46. builder.setTitle("检测到新版本");
  47. builder.setMessage("是否下载更新?");
  48. builder.setPositiveButton("下载", new DialogInterface.OnClickListener() {
  49. @Override
  50. public void onClick(DialogInterface dialog, int which) {
  51. // TODO Auto-generated method stub
  52. Intent it = new Intent(Main.this, NotificationUpdateActivity.class);
  53. startActivity(it);
  54. //              MapApp.isDownload = true;
  55. app.setDownload(true);
  56. }
  57. }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
  58. @Override
  59. public void onClick(DialogInterface dialog, int which) {
  60. // TODO Auto-generated method stub
  61. }
  62. });
  63. builder.show();
  64. }
  65. }

NotificationUpdateActivity    这个我加了一个启动模式 SingleTask

  1. package com.zeng.update;
  2. import com.zeng.update.DownloadService.DownloadBinder;
  3. import android.app.Activity;
  4. import android.content.ComponentName;
  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.content.ServiceConnection;
  8. import android.content.SharedPreferences;
  9. import android.os.Bundle;
  10. import android.os.Handler;
  11. import android.os.IBinder;
  12. import android.view.View;
  13. import android.view.View.OnClickListener;
  14. import android.widget.Button;
  15. import android.widget.ProgressBar;
  16. import android.widget.TextView;
  17. public class NotificationUpdateActivity extends Activity {
  18. private Button btn_cancel;// btn_update,
  19. private TextView tv_progress;
  20. private DownloadBinder binder;
  21. private boolean isBinded;
  22. private ProgressBar mProgressBar;
  23. // 获取到下载url后,直接复制给MapApp,里面的全局变量
  24. private String downloadUrl;
  25. //
  26. private boolean isDestroy = true;
  27. private MyApp app;
  28. /** Called when the activity is first created. */
  29. @Override
  30. public void onCreate(Bundle savedInstanceState) {
  31. super.onCreate(savedInstanceState);
  32. setContentView(R.layout.update);
  33. app = (MyApp) getApplication();
  34. // btn_update = (Button) findViewById(R.id.update);
  35. btn_cancel = (Button) findViewById(R.id.cancel);
  36. tv_progress = (TextView) findViewById(R.id.currentPos);
  37. mProgressBar = (ProgressBar) findViewById(R.id.progressbar1);
  38. btn_cancel.setOnClickListener(new OnClickListener() {
  39. @Override
  40. public void onClick(View v) {
  41. // TODO Auto-generated method stub
  42. binder.cancel();
  43. binder.cancelNotification();
  44. finish();
  45. }
  46. });
  47. }
  48. ServiceConnection conn = new ServiceConnection() {
  49. @Override
  50. public void onServiceDisconnected(ComponentName name) {
  51. // TODO Auto-generated method stub
  52. isBinded = false;
  53. }
  54. @Override
  55. public void onServiceConnected(ComponentName name, IBinder service) {
  56. // TODO Auto-generated method stub
  57. binder = (DownloadBinder) service;
  58. System.out.println("服务启动!!!");
  59. // 开始下载
  60. isBinded = true;
  61. binder.addCallback(callback);
  62. binder.start();
  63. }
  64. };
  65. @Override
  66. protected void onResume() {
  67. // TODO Auto-generated method stub
  68. super.onResume();
  69. if (isDestroy && app.isDownload()) {
  70. Intent it = new Intent(NotificationUpdateActivity.this, DownloadService.class);
  71. startService(it);
  72. bindService(it, conn, Context.BIND_AUTO_CREATE);
  73. }
  74. System.out.println(" notification  onresume");
  75. }
  76. @Override
  77. protected void onNewIntent(Intent intent) {
  78. // TODO Auto-generated method stub
  79. super.onNewIntent(intent);
  80. if (isDestroy && app.isDownload()) {
  81. Intent it = new Intent(NotificationUpdateActivity.this, DownloadService.class);
  82. startService(it);
  83. bindService(it, conn, Context.BIND_AUTO_CREATE);
  84. }
  85. System.out.println(" notification  onNewIntent");
  86. }
  87. @Override
  88. protected void onStart() {
  89. // TODO Auto-generated method stub
  90. super.onStart();
  91. }
  92. @Override
  93. protected void onPause() {
  94. // TODO Auto-generated method stub
  95. super.onPause();
  96. System.out.println(" notification  onPause");
  97. }
  98. @Override
  99. protected void onStop() {
  100. // TODO Auto-generated method stub
  101. super.onStop();
  102. isDestroy = false;
  103. System.out.println(" notification  onStop");
  104. }
  105. @Override
  106. protected void onDestroy() {
  107. super.onDestroy();
  108. if (isBinded) {
  109. System.out.println(" onDestroy   unbindservice");
  110. unbindService(conn);
  111. }
  112. if (binder != null && binder.isCanceled()) {
  113. System.out.println(" onDestroy  stopservice");
  114. Intent it = new Intent(this, DownloadService.class);
  115. stopService(it);
  116. }
  117. }
  118. private ICallbackResult callback = new ICallbackResult() {
  119. @Override
  120. public void OnBackResult(Object result) {
  121. // TODO Auto-generated method stub
  122. if ("finish".equals(result)) {
  123. finish();
  124. return;
  125. }
  126. int i = (Integer) result;
  127. mProgressBar.setProgress(i);
  128. // tv_progress.setText("当前进度 =>  "+i+"%");
  129. // tv_progress.postInvalidate();
  130. mHandler.sendEmptyMessage(i);
  131. }
  132. };
  133. private Handler mHandler = new Handler() {
  134. public void handleMessage(android.os.Message msg) {
  135. tv_progress.setText("当前进度 : " + msg.what + "%");
  136. };
  137. };
  138. public interface ICallbackResult {
  139. public void OnBackResult(Object result);
  140. }
  141. }

DownloadService

  1. package com.zeng.update;
  2. import java.io.File;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.net.HttpURLConnection;
  7. import java.net.MalformedURLException;
  8. import java.net.URL;
  9. import java.util.List;
  10. import com.zeng.update.NotificationUpdateActivity.ICallbackResult;
  11. import android.app.Notification;
  12. import android.app.NotificationManager;
  13. import android.app.PendingIntent;
  14. import android.app.Service;
  15. import android.content.Context;
  16. import android.content.Intent;
  17. import android.net.Uri;
  18. import android.os.Binder;
  19. import android.os.Handler;
  20. import android.os.IBinder;
  21. import android.os.Message;
  22. import android.widget.RemoteViews;
  23. public class DownloadService extends Service {
  24. private static final int NOTIFY_ID = 0;
  25. private int progress;
  26. private NotificationManager mNotificationManager;
  27. private boolean canceled;
  28. // 返回的安装包url
  29. private String apkUrl = "http://softfile.3g.qq.com:8080/msoft/179/24659/43549/qq_hd_mini_1.4.apk";
  30. // private String apkUrl = MyApp.downloadApkUrl;
  31. /* 下载包安装路径 */
  32. private static final String savePath = "/sdcard/updateApkDemo/";
  33. private static final String saveFileName = savePath + "3GQQ_AppUpdate.apk";
  34. private ICallbackResult callback;
  35. private DownloadBinder binder;
  36. private MyApp app;
  37. private boolean serviceIsDestroy = false;
  38. private Context mContext = this;
  39. private Handler mHandler = new Handler() {
  40. @Override
  41. public void handleMessage(Message msg) {
  42. // TODO Auto-generated method stub
  43. super.handleMessage(msg);
  44. switch (msg.what) {
  45. case 0:
  46. app.setDownload(false);
  47. // 下载完毕
  48. // 取消通知
  49. mNotificationManager.cancel(NOTIFY_ID);
  50. installApk();
  51. break;
  52. case 2:
  53. app.setDownload(false);
  54. // 这里是用户界面手动取消,所以会经过activity的onDestroy();方法
  55. // 取消通知
  56. mNotificationManager.cancel(NOTIFY_ID);
  57. break;
  58. case 1:
  59. int rate = msg.arg1;
  60. app.setDownload(true);
  61. if (rate < 100) {
  62. RemoteViews contentview = mNotification.contentView;
  63. contentview.setTextViewText(R.id.tv_progress, rate + "%");
  64. contentview.setProgressBar(R.id.progressbar, 100, rate, false);
  65. } else {
  66. System.out.println("下载完毕!!!!!!!!!!!");
  67. // 下载完毕后变换通知形式
  68. mNotification.flags = Notification.FLAG_AUTO_CANCEL;
  69. mNotification.contentView = null;
  70. Intent intent = new Intent(mContext, NotificationUpdateActivity.class);
  71. // 告知已完成
  72. intent.putExtra("completed", "yes");
  73. // 更新参数,注意flags要使用FLAG_UPDATE_CURRENT
  74. PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent,
  75. PendingIntent.FLAG_UPDATE_CURRENT);
  76. mNotification.setLatestEventInfo(mContext, "下载完成", "文件已下载完毕", contentIntent);
  77. //
  78. serviceIsDestroy = true;
  79. stopSelf();// 停掉服务自身
  80. }
  81. mNotificationManager.notify(NOTIFY_ID, mNotification);
  82. break;
  83. }
  84. }
  85. };
  86. //
  87. // @Override
  88. // public int onStartCommand(Intent intent, int flags, int startId) {
  89. // // TODO Auto-generated method stub
  90. // return START_STICKY;
  91. // }
  92. @Override
  93. public IBinder onBind(Intent intent) {
  94. // TODO Auto-generated method stub
  95. System.out.println("是否执行了 onBind");
  96. return binder;
  97. }
  98. @Override
  99. public void onDestroy() {
  100. // TODO Auto-generated method stub
  101. super.onDestroy();
  102. System.out.println("downloadservice ondestroy");
  103. // 假如被销毁了,无论如何都默认取消了。
  104. app.setDownload(false);
  105. }
  106. @Override
  107. public boolean onUnbind(Intent intent) {
  108. // TODO Auto-generated method stub
  109. System.out.println("downloadservice onUnbind");
  110. return super.onUnbind(intent);
  111. }
  112. @Override
  113. public void onRebind(Intent intent) {
  114. // TODO Auto-generated method stub
  115. super.onRebind(intent);
  116. System.out.println("downloadservice onRebind");
  117. }
  118. @Override
  119. public void onCreate() {
  120. // TODO Auto-generated method stub
  121. super.onCreate();
  122. binder = new DownloadBinder();
  123. mNotificationManager = (NotificationManager) getSystemService(android.content.Context.NOTIFICATION_SERVICE);
  124. setForeground(true);// 这个不确定是否有作用
  125. app = (MyApp) getApplication();
  126. }
  127. public class DownloadBinder extends Binder {
  128. public void start() {
  129. if (downLoadThread == null || !downLoadThread.isAlive()) {
  130. progress = 0;
  131. setUpNotification();
  132. new Thread() {
  133. public void run() {
  134. // 下载
  135. startDownload();
  136. };
  137. }.start();
  138. }
  139. }
  140. public void cancel() {
  141. canceled = true;
  142. }
  143. public int getProgress() {
  144. return progress;
  145. }
  146. public boolean isCanceled() {
  147. return canceled;
  148. }
  149. public boolean serviceIsDestroy() {
  150. return serviceIsDestroy;
  151. }
  152. public void cancelNotification() {
  153. mHandler.sendEmptyMessage(2);
  154. }
  155. public void addCallback(ICallbackResult callback) {
  156. DownloadService.this.callback = callback;
  157. }
  158. }
  159. private void startDownload() {
  160. // TODO Auto-generated method stub
  161. canceled = false;
  162. downloadApk();
  163. }
  164. //
  165. Notification mNotification;
  166. // 通知栏
  167. /**
  168. * 创建通知
  169. */
  170. private void setUpNotification() {
  171. int icon = R.drawable.icon;
  172. CharSequence tickerText = "开始下载";
  173. long when = System.currentTimeMillis();
  174. mNotification = new Notification(icon, tickerText, when);
  175. ;
  176. // 放置在"正在运行"栏目中
  177. mNotification.flags = Notification.FLAG_ONGOING_EVENT;
  178. RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification_layout);
  179. contentView.setTextViewText(R.id.name, "腾讯QQ.apk 正在下载...");
  180. // 指定个性化视图
  181. mNotification.contentView = contentView;
  182. Intent intent = new Intent(this, NotificationUpdateActivity.class);
  183. // 下面两句是 在按home后,点击通知栏,返回之前activity 状态;
  184. // 有下面两句的话,假如service还在后台下载, 在点击程序图片重新进入程序时,直接到下载界面,相当于把程序MAIN 入口改了 - -
  185. // 是这么理解么。。。
  186. // intent.setAction(Intent.ACTION_MAIN);
  187. // intent.addCategory(Intent.CATEGORY_LAUNCHER);
  188. PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent,
  189. PendingIntent.FLAG_UPDATE_CURRENT);
  190. // 指定内容意图
  191. mNotification.contentIntent = contentIntent;
  192. mNotificationManager.notify(NOTIFY_ID, mNotification);
  193. }
  194. //
  195. /**
  196. * 下载apk
  197. *
  198. * @param url
  199. */
  200. private Thread downLoadThread;
  201. private void downloadApk() {
  202. downLoadThread = new Thread(mdownApkRunnable);
  203. downLoadThread.start();
  204. }
  205. /**
  206. * 安装apk
  207. *
  208. * @param url
  209. */
  210. private void installApk() {
  211. File apkfile = new File(saveFileName);
  212. if (!apkfile.exists()) {
  213. return;
  214. }
  215. Intent i = new Intent(Intent.ACTION_VIEW);
  216. i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  217. i.setDataAndType(Uri.parse("file://" + apkfile.toString()), "application/vnd.android.package-archive");
  218. mContext.startActivity(i);
  219. callback.OnBackResult("finish");
  220. }
  221. private int lastRate = 0;
  222. private Runnable mdownApkRunnable = new Runnable() {
  223. @Override
  224. public void run() {
  225. try {
  226. URL url = new URL(apkUrl);
  227. HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  228. conn.connect();
  229. int length = conn.getContentLength();
  230. InputStream is = conn.getInputStream();
  231. File file = new File(savePath);
  232. if (!file.exists()) {
  233. file.mkdirs();
  234. }
  235. String apkFile = saveFileName;
  236. File ApkFile = new File(apkFile);
  237. FileOutputStream fos = new FileOutputStream(ApkFile);
  238. int count = 0;
  239. byte buf[] = new byte[1024];
  240. do {
  241. int numread = is.read(buf);
  242. count += numread;
  243. progress = (int) (((float) count / length) * 100);
  244. // 更新进度
  245. Message msg = mHandler.obtainMessage();
  246. msg.what = 1;
  247. msg.arg1 = progress;
  248. if (progress >= lastRate + 1) {
  249. mHandler.sendMessage(msg);
  250. lastRate = progress;
  251. if (callback != null)
  252. callback.OnBackResult(progress);
  253. }
  254. if (numread <= 0) {
  255. // 下载完成通知安装
  256. mHandler.sendEmptyMessage(0);
  257. // 下载完了,cancelled也要设置
  258. canceled = true;
  259. break;
  260. }
  261. fos.write(buf, 0, numread);
  262. } while (!canceled);// 点击取消就停止下载.
  263. fos.close();
  264. is.close();
  265. } catch (MalformedURLException e) {
  266. e.printStackTrace();
  267. } catch (IOException e) {
  268. e.printStackTrace();
  269. }
  270. }
  271. };
  272. }

参照博客

http://blog.csdn.net/liuhe688/article/details/6623924

还有些代码是另一个下载的demo的 不过忘了哪下的~

源码下载

http://download.csdn.net/detail/zgf1991/5725471

转 android客户端版本检测更新,服务下载,通知栏显示的更多相关文章

  1. 体验极速Android SDK的更新与下载

    首先:国内明确一点,国内由于天朝限制了google,更新和下载Android相关资料都比较吃力,因此,本文正式宣告,此问题不再是问题-------别说话,吻我 先给点福利: 关于java(Androi ...

  2. Android应用程序更新并下载

    创建一个新类,名为UpdateManager,代码如下: package com.af.service; import java.io.BufferedReader; import java.io.F ...

  3. android客户端app和服务端交互token的作用

    Android客户端和服务端如何使用Token和Session niceheart关注1人评论34644人阅读2014-09-16 16:38:44   对于初学者来说,对Token和Session的 ...

  4. 微信app支付android客户端以及.net服务端实现

    由于公司运营需要,需要在客户端(android/ios)增加微信以及支付宝支付,在调用微信app支付时遇到一些问题,也算是一些踩过的坑,记录下来 ,希望能对.net开发者服务端网站更快的集成微信app ...

  5. Android客户端与PC服务端、android服务端通过WiFi通信

    前期准备:我的是Linux Mint操作系统(总之折腾的过程中怀疑过是不是系统的问题),首先是要创建wifi热点给android手机使用,这个时候笔记本作为通信的服务器端,android手机作为客户端 ...

  6. Android客户端与PHP服务端交互(一)---框架概述

    背景 作为一个普通上班族,总是想做一些自认为有意义的事情,于是乎准备成立一个工作室,尽管目前正在筹备阶段,但是之前有些朋友提出一些需求的时候,我发现自己的能力还是有限,直到最近和一些技术牛朋友聊起这事 ...

  7. 解决Android SDK Manager 更新、下载慢以及待安装包列表不显示

    参考地址:http://www.cnblogs.com/tc310/archive/2012/12/21/2828450.html 问题描述: Android SDK Manager 无法下载更新,或 ...

  8. Android客户端中Bitmap的下载过程和缓存机制

    加载流程: if(内存命中){      从内存中读取 }else{      create AsyncTasks,task中的多个Runnable是通过堆栈先进后出的方式来调度,而非队列式的先进先出 ...

  9. android客户端向java服务端post发送json

    android 端: private void HttpPostData() {        try { HttpClient httpclient = new DefaultHttpClient( ...

随机推荐

  1. 手机版WEB开发经验分享,手机版网站开发注意事项,网站自适应,手机版网站自适应,移动安卓APP自适应

    转自 http://my.oschina.net/cart/blog/282477 做前端开发不短了,用过jQuery Mobile jqMobi 也纯手工写过.. 最后总结如下: jQuery Mo ...

  2. QML中MouseArea元素的介绍

    原文:http://www.thisisqt.com/?action-viewnews-itemid-22 MouseArea元素的一个很典型的用法是和一个可视的item一起用,处理这个item的鼠标 ...

  3. Git Server和sourceTree客户端使用说明

    一.创建本地仓库 新建一个文件夹,命名为LocalRep,来作为本地仓库. 在终端 cd+拖拽文件夹到终端,打开文件夹在LocalRep目录下操作clone远程仓库到本地,指令如下所示(需根据实际情况 ...

  4. IO流---字符流(FileWriter, FileReader ,BufferedWriter,BufferedReader)

    IO   Input  Output IO流用来处理设备之间的数据传输. java对数据的操作是通过流来实现的. 流按流向分:输入流,输出流     是相对内存而言的.把硬盘的数据读取到内存中就是输入 ...

  5. GCC: compilation process..

    gcc -Iproj/src myfile.c -o myfile gcc -c myfile.c "compile without linking gcc -D DEBUG myfile. ...

  6. php实现echo json_encode正确显示汉字

    <?php header('Content-type: text/html; charset=utf-8'); /* function showmessage($msg = '', $redir ...

  7. IDAPython: importing “site” failed

    问题:IDA启动时,弹出IDAPython: importing “site” failed对话框. 解决办法:环境变量添加PYTHONHOME,值为python安装路径,比如:C:\Python27

  8. SuperSocket+unity 网络笔记

    学习SuperSocket 必须要注意的 代码是 static void Main(string[] args) { WebSocketServer appServer = new WebSocket ...

  9. POJ 2084 Game of Connections(卡特兰数)

    卡特兰数源于组合数学,ACM中比较具体的使用例子有,1括号匹配的种数.2在栈中的自然数出栈的种数.3求多边形内三角形的个数.4,n个数围城圆圈,找不相交线段的个数.5给定n个数,求组成二叉树的种数…… ...

  10. windbg 之 如何设置模块加载时断下

    这里先介绍两个指令: sx指令: The sx* commands control the action that the debugger takes when an exception occur ...