简单记录一下四大组件之一的Service的简单实用。

先是最简单的用法,服务的开关,onBind方法的使用

  1. package com.example.wkp.service;
  2.  
  3. import android.content.ComponentName;
  4. import android.content.Intent;
  5. import android.content.ServiceConnection;
  6. import android.os.IBinder;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.os.Bundle;
  9. import android.util.Log;
  10. import android.view.View;
  11. import android.widget.Button;
  12.  
  13. public class MainActivity extends AppCompatActivity {
  14. private Button start=null;
  15. private Button stop=null;
  16. private Button bind=null;
  17. private Button unbind=null;
  18. private Button get=null;
  19. private MyService.MyBinder binder;
  20. private ServiceConnection connection=new ServiceConnection() {
  21. @Override
  22. public void onServiceConnected(ComponentName name, IBinder service) {
  23. //得到返回值binder
  24. binder= (MyService.MyBinder) service;
  25. //使用binder中的方法
  26. Log.v("qq",String.valueOf(binder.getNum()));
  27. }
  28.  
  29. @Override
  30. public void onServiceDisconnected(ComponentName name) {
  31.  
  32. }
  33. };
  34. @Override
  35. protected void onCreate(Bundle savedInstanceState) {
  36. super.onCreate(savedInstanceState);
  37. setContentView(R.layout.activity_main);
  38. start= (Button) findViewById(R.id.start);
  39. stop=(Button)findViewById(R.id.stop);
  40. bind=(Button)findViewById(R.id.bind);
  41. unbind=(Button)findViewById(R.id.unbind);
  42. get=(Button)findViewById(R.id.getnum);
  43.  
  44. final Intent intent=new Intent();
  45. //跳转到配置文件中定义的intent-filter
  46. // intent.setAction("SERVICE");
  47. // intent.setPackage(getPackageName());
  48. intent.setClass(MainActivity.this,MyService.class);
  49.  
  50. start.setOnClickListener(new View.OnClickListener() {
  51. @Override
  52. public void onClick(View v) {
  53. startService(intent);
  54. }
  55. });
  56.  
  57. stop.setOnClickListener(new View.OnClickListener() {
  58. @Override
  59. public void onClick(View v) {
  60. stopService(intent);
  61. }
  62. });
  63.  
  64. bind.setOnClickListener(new View.OnClickListener(){
  65.  
  66. @Override
  67. public void onClick(View v) {
  68. bindService(intent,connection,BIND_AUTO_CREATE);
  69. }
  70. });
  71.  
  72. unbind.setOnClickListener(new View.OnClickListener(){
  73.  
  74. @Override
  75. public void onClick(View v) {
  76. unbindService(connection);
  77. }
  78. });
  79.  
  80. get.setOnClickListener(new View.OnClickListener(){
  81.  
  82. @Override
  83. public void onClick(View v) {
  84. Log.v("qq",String.valueOf(binder.getNum()));
  85. }
  86. });
  87.  
  88. // class btnListener implements View.OnClickListener{
  89. //
  90. // @Override
  91. // public void onClick(View v) {
  92. // switch(v.getId()){
  93. // case R.id.bind:
  94. // bindService(intent,connection,BIND_AUTO_CREATE);
  95. // break;
  96. // case R.id.unbind:
  97. // unbindService(connection);
  98. // break;
  99. // case R.id.getnum:
  100. // Log.v("qq",String.valueOf(binder.getNum()));
  101. // break;
  102. // default:
  103. // break;
  104. // }
  105. // }
  106. // }
  107. }
  108. }

MainActivity.java

  1. package com.example.wkp.service;
  2.  
  3. import android.app.Service;
  4. import android.content.Intent;
  5. import android.os.Binder;
  6. import android.os.IBinder;
  7. import android.support.annotation.Nullable;
  8. import android.util.Log;
  9. import android.widget.Button;
  10.  
  11. /**
  12. * Created by wkp on 2016/9/22.
  13. */
  14. public class MyService extends Service {
  15.  
  16. int num=0;
  17. MyBinder binder=new MyBinder();
  18.  
  19. @Nullable
  20. @Override
  21. public IBinder onBind(Intent intent) {
  22. Log.v("oo","binder");
  23. return binder;
  24. }
  25.  
  26. @Override
  27. public void onCreate() {
  28. super.onCreate();
  29. Log.v("hehe","service create");
  30. num+=10;
  31. }
  32.  
  33. @Override
  34. public void onStart(Intent intent, int startId) {
  35. super.onStart(intent, startId);
  36. Log.v("hehe","service start");
  37. }
  38.  
  39. @Override
  40. public void onDestroy() {
  41. super.onDestroy();
  42. Log.v("hehe","service destory");
  43. }
  44.  
  45. //创建一个Binder,用来在onBind中返回
  46. class MyBinder extends Binder{
  47. int getNum(){
  48. return num;
  49. }
  50. }
  51. }

MyService.java

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:orientation="vertical"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:paddingBottom="@dimen/activity_vertical_margin"
  8. android:paddingLeft="@dimen/activity_horizontal_margin"
  9. android:paddingRight="@dimen/activity_horizontal_margin"
  10. android:paddingTop="@dimen/activity_vertical_margin"
  11. tools:context="com.example.wkp.service.MainActivity">
  12.  
  13. <TextView
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:text="Hello World!" />
  17.  
  18. <Button android:id="@+id/start"
  19. android:layout_width="match_parent"
  20. android:layout_height="wrap_content"
  21. android:text="start"/>
  22.  
  23. <Button android:id="@+id/stop"
  24. android:layout_width="match_parent"
  25. android:layout_height="wrap_content"
  26. android:text="stop"/>
  27.  
  28. <Button android:id="@+id/bind"
  29. android:layout_width="match_parent"
  30. android:layout_height="wrap_content"
  31. android:text="bind"/>
  32.  
  33. <Button android:id="@+id/unbind"
  34. android:layout_width="match_parent"
  35. android:layout_height="wrap_content"
  36. android:text="unbind"/>
  37.  
  38. <Button android:id="@+id/getnum"
  39. android:layout_width="match_parent"
  40. android:layout_height="wrap_content"
  41. android:text="getnum"/>
  42. </LinearLayout>

activity_main.xml

在AndroidManifest.xml中注册服务

然后是前台服务和IntentService。就是手机屏幕左上角弹出来的小图标,和广播结合有点类似推送。

  1. package com.example.wkp.service;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.widget.Button;
  8.  
  9. /**
  10. * Created by wkp on 2016/9/24.
  11. */
  12. public class SecondActivity extends Activity {
  13.  
  14. private Button startFore=null;
  15. private Button stopFore=null;
  16. private Button startIntent=null;
  17. private Button stopIntent=null;
  18. private Intent intent1,intent2=null;
  19.  
  20. @Override
  21. protected void onCreate(Bundle savedInstanceState) {
  22. super.onCreate(savedInstanceState);
  23. setContentView(R.layout.activity_second);
  24. init();
  25. intent1=new Intent(SecondActivity.this,MyService2.class);
  26. intent2=new Intent(SecondActivity.this,MyIntentService.class);
  27. }
  28.  
  29. //按钮控件初始化
  30. void init(){
  31. startFore= (Button) findViewById(R.id.startFore);
  32. stopFore=(Button)findViewById(R.id.startFore);
  33. startIntent=(Button) findViewById(R.id.startIntent);
  34. stopIntent=(Button) findViewById(R.id.stopIntent);
  35.  
  36. startFore.setOnClickListener(new btnListener());
  37. stopFore.setOnClickListener(new btnListener());
  38. startIntent.setOnClickListener(new btnListener());
  39. stopIntent.setOnClickListener(new btnListener());
  40. }
  41.  
  42. class btnListener implements View.OnClickListener{
  43.  
  44. @Override
  45. public void onClick(View v) {
  46. switch(v.getId()){
  47. case R.id.startFore:
  48. startService(intent1);
  49. break;
  50. case R.id.stopFore:
  51. break;
  52. case R.id.startIntent:
  53. startService(intent2);
  54. break;
  55. case R.id.stopIntent:
  56. stopService(intent2);
  57. break;
  58. default:break;
  59. }
  60. }
  61. }
  62. }

SecondActivity.java

  1. package com.example.wkp.service;
  2.  
  3. import android.app.Notification;
  4. import android.app.PendingIntent;
  5. import android.app.Service;
  6. import android.content.Intent;
  7. import android.os.IBinder;
  8. import android.support.annotation.Nullable;
  9. import android.widget.RemoteViews;
  10.  
  11. /**
  12. * Created by wkp on 2016/9/24.
  13. */
  14. public class MyService2 extends Service{
  15. @Nullable
  16. @Override
  17. public IBinder onBind(Intent intent) {
  18. return null;
  19. }
  20.  
  21. @Override
  22. public void onCreate() {
  23. super.onCreate();
  24. //创建通知实例
  25. Notification notification=new Notification();
  26. //图标
  27. notification.icon=R.drawable.books;
  28. //内容
  29. notification.contentView=new RemoteViews(getPackageName(),R.layout.notify);
  30. //跳转
  31. notification.contentIntent= PendingIntent.getActivity(this,0,new Intent(this,SecondActivity.class),0);
  32. //开启
  33. startForeground(1,notification);
  34. }
  35. }

MyService2.java

  1. package com.example.wkp.service;
  2.  
  3. import android.app.IntentService;
  4. import android.app.Service;
  5. import android.content.Intent;
  6. import android.os.IBinder;
  7. import android.support.annotation.Nullable;
  8. import android.util.Log;
  9.  
  10. /**
  11. * Created by wkp on 2016/9/24.
  12. */
  13. public class MyIntentService extends IntentService{
  14.  
  15. /**
  16. * Creates an IntentService. Invoked by your subclass's constructor.
  17. *
  18. * @param name Used to name the worker thread, important only for debugging.
  19. */
  20. public MyIntentService(String name) {
  21. super(name);
  22. }
  23.  
  24. //必须创建一个无参的构造方法
  25. public MyIntentService(){
  26. super("MyIntentService");
  27. }
  28.  
  29. //开启一个新的线程,可以进行耗时操作
  30. @Override
  31. protected void onHandleIntent(Intent intent) {
  32. Log.v("haha","onhandle");
  33. Log.v("hehe",String.valueOf(Thread.currentThread().getId()));
  34. Log.v("hehe",String.valueOf(android.os.Process.myPid()));
  35. while(true){
  36. try{
  37. Thread.sleep(1000);
  38. Log.v("pp","I am in handle");
  39. }catch(Exception e){
  40. e.printStackTrace();
  41. }
  42.  
  43. }
  44. }
  45.  
  46. @Override
  47. public void onCreate() {
  48. super.onCreate();
  49. Log.v("haha","oncreate");
  50. Log.v("hehe",String.valueOf(Thread.currentThread().getId()));
  51. Log.v("hehe",String.valueOf(android.os.Process.myPid()));
  52. }
  53.  
  54. @Override
  55. public void onDestroy() {
  56. super.onDestroy();
  57. Log.v("haha","ondestroy");
  58. Log.v("hehe",String.valueOf(Thread.currentThread().getId()));
  59. Log.v("hehe",String.valueOf(android.os.Process.myPid()));
  60. }
  61. }

MyIntentService.java

Service和IntentService的区别是后者开启新的线程可以进行耗时操作。

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical" android:layout_width="match_parent"
  4. android:layout_height="match_parent">
  5.  
  6. <Button android:id="@+id/startFore"
  7. android:layout_width="match_parent"
  8. android:layout_height="wrap_content"
  9. android:text="startFore"/>
  10.  
  11. <Button android:id="@+id/stopFore"
  12. android:layout_width="match_parent"
  13. android:layout_height="wrap_content"
  14. android:text="stopFore"/>
  15.  
  16. <Button android:id="@+id/startIntent"
  17. android:layout_width="match_parent"
  18. android:layout_height="wrap_content"
  19. android:text="startIntent"/>
  20.  
  21. <Button android:id="@+id/stopIntent"
  22. android:layout_width="match_parent"
  23. android:layout_height="wrap_content"
  24. android:text="stopIntent"/>
  25. </LinearLayout>

activity_second.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical" android:layout_width="match_parent"
  4. android:layout_height="match_parent">
  5.  
  6. <ImageView
  7. android:src="@drawable/books"
  8. android:layout_width="wrap_content"
  9. android:layout_height="wrap_content" />
  10.  
  11. <TextView
  12. android:layout_width="wrap_content"
  13. android:layout_height="wrap_content"
  14. android:text="前台服务"/>
  15. </LinearLayout>

notify.xml

最后Service和Broadcast Receiver结合做一个定点报时

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3. package="com.example.wkp.clock">
  4.  
  5. <application
  6. android:allowBackup="true"
  7. android:icon="@mipmap/ic_launcher"
  8. android:label="@string/app_name"
  9. android:supportsRtl="true"
  10. android:theme="@style/AppTheme">
  11. <activity android:name=".MainActivity">
  12. <intent-filter>
  13. <action android:name="android.intent.action.MAIN" />
  14.  
  15. <category android:name="android.intent.category.LAUNCHER" />
  16. </intent-filter>
  17. </activity>
  18.  
  19. <service android:name=".AlarmService">
  20.  
  21. </service>
  22.  
  23. <receiver android:name=".AlarmReceiver">
  24. <intent-filter>
  25. <action android:name="ALARM_ACTION" />
  26. </intent-filter>
  27. </receiver>
  28. </application>
  29.  
  30. </manifest>

AndroidManifest.xml

  1. package com.example.wkp.clock;
  2.  
  3. import android.content.ComponentName;
  4. import android.content.Intent;
  5. import android.content.ServiceConnection;
  6. import android.os.IBinder;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.os.Bundle;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.EditText;
  12.  
  13. public class MainActivity extends AppCompatActivity {
  14.  
  15. private Button start=null;
  16. private Button stop=null;
  17. private EditText edit=null;
  18. private Intent intent = null;
  19. private AlarmService.AlarmBinder binder;
  20.  
  21. private ServiceConnection connection=new ServiceConnection() {
  22. @Override
  23. public void onServiceConnected(ComponentName name, IBinder service) {
  24. binder=(AlarmService.AlarmBinder)service;
  25. }
  26.  
  27. @Override
  28. public void onServiceDisconnected(ComponentName name) {
  29.  
  30. }
  31. };
  32.  
  33. @Override
  34. protected void onCreate(Bundle savedInstanceState) {
  35. super.onCreate(savedInstanceState);
  36. setContentView(R.layout.activity_main);
  37. init();
  38. }
  39.  
  40. void init(){
  41. start= (Button) findViewById(R.id.start);
  42. stop= (Button) findViewById(R.id.stop);
  43. edit=(EditText)findViewById(R.id.edit);
  44.  
  45. start.setOnClickListener(new btnListener());
  46. stop.setOnClickListener(new btnListener());
  47.  
  48. //绑定服务
  49. intent=new Intent(this,AlarmService.class);
  50. bindService(intent,connection,BIND_AUTO_CREATE);
  51. }
  52.  
  53. class btnListener implements View.OnClickListener{
  54.  
  55. @Override
  56. public void onClick(View v) {
  57. switch (v.getId()){
  58. case R.id.start:
  59. binder.setTime(Integer.parseInt(edit.getText().toString()));
  60. startService(intent);
  61. break;
  62. case R.id.stop:
  63. binder.setState();
  64. break;
  65. default:
  66. break;
  67. }
  68. }
  69. }
  70. }

MainActivity.java

  1. package com.example.wkp.clock;
  2.  
  3. import android.app.AlarmManager;
  4. import android.app.Notification;
  5. import android.app.PendingIntent;
  6. import android.app.Service;
  7. import android.content.Intent;
  8. import android.os.Binder;
  9. import android.os.IBinder;
  10. import android.os.SystemClock;
  11. import android.support.annotation.Nullable;
  12. import android.util.Log;
  13. import android.widget.RemoteViews;
  14.  
  15. /**
  16. * Created by wkp on 2016/9/24.
  17. */
  18. public class AlarmService extends Service {
  19.  
  20. private AlarmBinder binder = new AlarmBinder();
  21. private AlarmManager manager;
  22. private Intent intent1;
  23. private PendingIntent pd;
  24. private int time;
  25. private boolean flag=true;
  26.  
  27. @Nullable
  28. @Override
  29. public IBinder onBind(Intent intent) {
  30.  
  31. //得到manager
  32. manager = (AlarmManager) getSystemService(ALARM_SERVICE);
  33. intent1 = new Intent(this, AlarmReceiver.class);
  34. intent1.setAction("ALARM_ACTION");
  35. //得到PendingIntent
  36. pd = PendingIntent.getBroadcast(this, 0, intent1, 0);
  37. return binder;
  38. }
  39.  
  40. @Override
  41. public void onCreate() {
  42. super.onCreate();
  43. //创建通知实例
  44. Notification notification = new Notification();
  45. //图标
  46. notification.icon = R.drawable.books;
  47. //内容
  48. notification.contentView = new RemoteViews(getPackageName(), R.layout.notify);
  49. //跳转
  50. notification.contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
  51. //开启
  52. startForeground(1, notification);
  53. }
  54.  
  55. @Override
  56. public int onStartCommand(Intent intent, int flags, int startId) {
  57. //设置闹钟
  58. //类型,开机到现在的时间||1970.1.1到现在的时间||。。。wakeup唤醒CPU
  59. //具体时间计算,单位毫秒
  60. //闹钟的意图
  61. Log.v("hehe","alarm");
  62. if(flag){
  63. manager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+time*1000,pd);
  64. }else{
  65. manager.cancel(pd);
  66. stopSelf();
  67. }
  68. return super.onStartCommand(intent, flags, startId);
  69. }
  70.  
  71. class AlarmBinder extends Binder {
  72. void setTime(int t){
  73. time=t;
  74. flag=true;
  75. }
  76.  
  77. void setState(){
  78. flag=false;
  79. }
  80.  
  81. }
  82. }

AlarmService.java

  1. package com.example.wkp.clock;
  2.  
  3. import android.content.BroadcastReceiver;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.util.Log;
  7.  
  8. /**
  9. * Created by wkp on 2016/9/24.
  10. */
  11. public class AlarmReceiver extends BroadcastReceiver {
  12. @Override
  13. public void onReceive(Context context, Intent intent) {
  14. Log.v("hehe","receiver");
  15. context.startService(new Intent(context,AlarmService.class));
  16. }
  17. }

AlarmReceiver.java

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:orientation="vertical"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:paddingBottom="@dimen/activity_vertical_margin"
  8. android:paddingLeft="@dimen/activity_horizontal_margin"
  9. android:paddingRight="@dimen/activity_horizontal_margin"
  10. android:paddingTop="@dimen/activity_vertical_margin"
  11. tools:context="com.example.wkp.clock.MainActivity">
  12.  
  13. <EditText
  14. android:id="@+id/edit"
  15. android:layout_width="match_parent"
  16. android:layout_height="wrap_content"/>
  17.  
  18. <Button android:id="@+id/start"
  19. android:layout_width="match_parent"
  20. android:layout_height="wrap_content"
  21. android:text="启动"/>
  22.  
  23. <Button android:id="@+id/stop"
  24. android:layout_width="match_parent"
  25. android:layout_height="wrap_content"
  26. android:text="关闭"/>
  27. </LinearLayout>

activity_main.xml

android入门——Service的更多相关文章

  1. android 入门-Service实时向Activity通过BroadcastReceiver传递数据

    引文: http://www.cnblogs.com/linjiqin/p/3147764.html <RelativeLayout xmlns:android="http://sch ...

  2. android 入门-Service

    sdk 1.7 package com.example.hellowrold; import java.util.Random; import com.example.hellowrold.R.id; ...

  3. android入门 — Service

    Service完全在后台运行,没有用户界面.使用的时候先创建Service子类,然后在AndroidManifest.xml中进行注册,同时可以通过<intent-filter.../>进 ...

  4. Android入门:Service入门介绍

    一.Service介绍 Service类似于Windows中的服务,没有界面,只是在后台运行:而服务不能自己运行,而是需要调用Context.startService(Intent intent);或 ...

  5. Android入门:绑定本地服务

    一.绑定服务介绍   前面文章中讲过一般的通过startService开启的服务,当访问者关闭时,服务仍然存在: 但是如果存在这样一种情况:访问者需要与服务进行通信,则我们需要将访问者与服务进行绑定: ...

  6. Android入门教程之我见

    真正的从安卓入门学习到实际工作也差不多一年时间了,也做了几个项目.在这期间经历了一开始学习Android的基本知识后仍旧无从下手,不知道如何开始开发一个app,到现在也开始学会注意Android架构的 ...

  7. 小猪的Android入门之路 day 1

    小猪的Android入门之路 Day 1 Android相关背景与开发环境的搭建 ------转载请注明出处:coder-pig 本节引言: 随着社会经济的发展,移动互联网的越来越热,手机APP开发显 ...

  8. 【详细】Android入门到放弃篇-YES OR NO-》各种UI组件,布局管理器,单元Activity

    问:达叔,你放弃了吗? 答:不,放弃是不可能的,丢了Android,你会心疼吗?如果别人把你丢掉,你是痛苦呢?还是痛苦呢?~ 引导语 有人说,爱上一个人是痛苦的,有人说,喜欢一个人是幸福的. 人与人之 ...

  9. Android精通教程-第一节Android入门简介

    前言 大家好,给大家带来Android精通教程-第一节Android入门简介的概述,希望你们喜欢 每日一句 If life were predictable it would cease to be ...

随机推荐

  1. Android的读写文件权限

    设置文件生成的权限: public static boolean saveInfo( Context context, String userName, String userPass, int mo ...

  2. ASP.NET State Service

    本文来自:http://www.cnblogs.com/jhxk/articles/1648194.html 这一段就是配置应用程序是如何存储Session信息的了.我们以下的各种操作主要是针对这一段 ...

  3. 热烈祝贺Polymer中文组织站点上线

    欢迎来到前端世界的明天 由于官网被墙, 所以 http://docs.polymerchina.org/ 其实是一件很有意义的事. 组件化和重用,一直是编程界几十年来前进的方向和目标,随着时间的推移和 ...

  4. 模块化利器:RequireJS常用知识

    1. 模块化 目前常见的模块化开发方式,全局空间方式是最基本的一种,另外常见的还有遵循AMD规范的开发方式,遵循CMD规范的开发方式,和ECMAScript 6的开发方式.需要说明的是,CMD和ES6 ...

  5. (原)前端知识杂烩(meta系列)

    更新于 20160831 1. meta 移动端头文件设置 (一般情况下,逐条复制放在头部就可以了) 1.1 强制让文档的宽度与设备的宽度保持1:1,并且文档最大的宽度比例是1.0,且不允许用户点击屏 ...

  6. Struts2 访问web元素

    访问web元素的四种方法(耦合,依赖注入).(耦合,非依赖注入).(非耦合,依赖注入).(非耦合,非依赖注入) 耦合:可以得到HttpServletResponse,HttpServletReques ...

  7. HTML7常用的类型刮刮乐 光棒效果

    常用的类型: 1.数学: Math.ceil():天花板数 Math.floor():地板数 Math.round():四舍五入取整数 Math.random():生成0-1之间的随机数   2.日期 ...

  8. css画图形

    博客:  史上最强大的40多个纯cs图形 问题:看了上面的博客思考简单的三角行是怎么形成的? #triangle-up { width: 0; height: 0; border-left: 50px ...

  9. EC读书笔记系列之20:条款53、54、55

    条款53 不要轻忽编译器的警告 记住: ★严肃对待编译器发出的警告信息.努力在你的编译器的最高(最严苛)警告级别下争取“无任何警告”的荣誉 ★不要过度依赖编译器的报警能力,∵不同的编译器对待事情的态度 ...

  10. Binder的使用(跨进程——AIDL,非跨进程)

    一.Binder类 1.作用:Binder是客户端与服务器端的通信的媒介(连接各种Manager的桥梁),客户端通过Binder对象获取服务器端提供的数据 (为什么要用Binder来提供数据呢,服务器 ...