上一页 1 ··· 22 23 24 25 26
摘要: 在Android的应用中,往往需要在执行主界面的操作时,如果要执行耗时的操作,那么应该是另外开线程的,或者是用async或者handler,今天发现其实也可以用android中的一个Intentservice去实现。下面例子讲解下。 1 例子中是一个文本框,当用户输入内容后,模拟slepp 10秒,这个时候要是不分离线程,操作的话,用户再点界面,就会死死地停在那里,甚至是出现提示,要强行CLOSE,代码如下: EditText input = (EditText) findViewById(R.id.txt_input); String strInputMsg = input.getText( 阅读全文
posted @ 2012-07-14 15:22 water0504 阅读(203) 评论(0) 推荐(0) 编辑
摘要: IntentService是Service类的子类,用来处理异步请求。客户端可以通过startService(Intent)方法传递请求给IntentService,IntentService通过worker thread处理每个Intent对象,执行完所有的工作之后自动停止Service。 说明:worker thread处理所有通过传递过来的请求,创建一个worker queue,一次只传递一个intent到onHandleIntent中,从而不必担心多线程带来的问题。处理完毕之后自动调用stopSelf()方法;默认实现了Onbind()方法,返回值为null; 模式实现了哦你Sta.. 阅读全文
posted @ 2012-07-14 15:17 water0504 阅读(369) 评论(0) 推荐(0) 编辑
摘要: Android程序中访问资源时需要提供Context,一般来说只有在各种component中(Activity, Provider等等)才能方便的使用api来获取Context, 而在某些工具类中要获取就很麻烦了。为此,我们可以自定义一个Application类来实现这种功能。import android.app.Application;public class MyApplication extends Application {private static MyApplication instance;public static MyApplication getInstance() {r 阅读全文
posted @ 2012-07-14 14:46 water0504 阅读(534) 评论(0) 推荐(0) 编辑
摘要: 1、给EditText追加ChangedListenerEditText editText = (EditText) findViewById(R.id.edittext);editText.addTextChangedListener(watcher); 2、描述监听private TextWatcher watcher = new TextWatcher() {@Overridepublic void onTextChanged(CharSequence s, int start, int before, int count) {// TODO Auto-generated method 阅读全文
posted @ 2012-07-14 14:26 water0504 阅读(689) 评论(0) 推荐(0) 编辑
摘要: 被判断的Service 必须是带包名的全名通过Service的类名来判断是否启动某个服务 private boolean MusicServiceIsStart(List<ActivityManager.RunningServiceInfo> mServiceList,String className){ for(int i = 0; i < mServiceList.size(); i ++){ if(className.equals(mServiceList.get(i).service.getClassName())){ ... 阅读全文
posted @ 2012-07-14 14:14 water0504 阅读(881) 评论(0) 推荐(0) 编辑
摘要: 一、判断网络连接是否可用public static boolean isNetworkAvailable(Context context) { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (cm == null) { } else { //如果仅仅是用来判断网络连接 //则可以使用 cm.getActive... 阅读全文
posted @ 2012-07-14 14:12 water0504 阅读(238) 评论(0) 推荐(0) 编辑
摘要: 1、按字节读取文件内容2、按字符读取文件内容3、按行读取文件内容4、随机读取文件内容 public class ReadFromFile { /** * 以字节为单位读取文件,常用于读二进制文件,如图片、声音、影像等文件。 */ public static void readFileByBytes(String fileName) { File file = new File(fileName); InputStream in = null; try { System.out.println("以字节为... 阅读全文
posted @ 2012-07-12 19:30 water0504 阅读(277) 评论(0) 推荐(0) 编辑
摘要: 什么是URI?Web上可用的每种资源如 HTML文档、图像、视频片段、程序等 都是一个通用资源标志符来(Universal Resource Identifier, 简称"URI")定位的。URI一般由三部分组1、访问资源的命名机制。 2、存放资源的主机名。 3、 资源自身的名称,由路径表示。 考虑下面的URI,它表示了当前的HTML 4.0规范http://www.tf988.com.com/html/html40/这个URI是这样的:这是一个可通过HTTP协议访问的资源,位于主机www.webmonkey.com.cn上,通过路径“/html/html40”访问。在HT 阅读全文
posted @ 2012-07-12 19:09 water0504 阅读(166) 评论(0) 推荐(0) 编辑
上一页 1 ··· 22 23 24 25 26