strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Intent</string>
<string name="start">开始</string>
<string name="stop">停止</string>
</resources>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:id="@+id/startButtonId" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="center"
android:text="@string/start" android:layout_margin="10px" />
<Button android:id="@+id/stopButtonId" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="center"
android:text="@string/stop" android:layout_margin="10px" />
</LinearLayout>
IntentActivity.java
package com.duoguo.android;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
/**
* Intent的使用
*
* @author shyboy(897948924@qq.com)
*
*/
public class IntentActivity extends Activity {
// 声明Button控件
private Button startButton;
private Button stopButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 根据Button控件的id获取控件对象
startButton = (Button) findViewById(R.id.startButtonId);
stopButton = (Button) findViewById(R.id.stopButtonId);
startButton.setOnClickListener(new StartButtonClickListener());// 为startButton添加单击事件监听器
stopButton.setOnClickListener(new StopButtonClickListener());// 为stopButton添加单击事件监听器
}
// 声明startButton控件的监听器
class StartButtonClickListener implements OnClickListener {
@Override
public void onClick(View v) {
handler.post(runnable);// 将线程添加到消息队列中
}
}
// 声明stopButton控件的监听器
class StopButtonClickListener implements OnClickListener {
@Override
public void onClick(View v) {
handler.removeCallbacks(runnable);// 在消息队列中将行将发生的post进行移除
}
}
Handler handler = new Handler();// 实例化Handler对象
// 实例化线程runnable对象
Runnable runnable = new Runnable() {
@Override
public void run() {
System.out.println("runnable……");
handler.postDelayed(runnable, 3000);// 在3秒时间过后将线程添加到消息队列中
}
};
}
希望能够给你带来帮助
分享到:
相关推荐
Android中Intent使用、数据回写(显)
源程序关于android平台中intent的使用小示例,仅供参考
通过一个实验,讲解Android的使用方法,总结详细
android activityIntent 传值 传对象
Java中使用的是Serializable,而谷歌在Android使用了自定义的Parcelable。 两种序列化方式的区别: 1.在使用内存的时候,Parcelable比Serializable性能高,推荐使用Parcelable类; 2.Serializable在序列化的时候会...
本文件介绍的是Anroid中Intent的使用方法,从谷歌中搜索内容;浏览网页;显示地图;路径规划;拨打电话;发送短信等简单功能实现
主要为大家详细介绍了Android利用Intent启动和关闭Activity的相关操作,感兴趣的小伙伴们可以参考一下
android中Intent传递对象的两种方法(Serializable,Parcelable) 简单而又详细的demo,欢迎下载
Android使用Intent实现Video功能
Android使用Intent实现Camera功能
Android+Intent机制实例详解 Android+Intent 大家不得不看啊!
可运行的Jar 博文链接:https://shenjichao2009.iteye.com/blog/1186319
android Intent例子源码android Intent例子源码android Intent例子源码android Intent例子源码android Intent例子源码android Intent例子源码
Android-Intent使用方法详解 配合(http://blog.csdn.net/daiyibo123/article/details/51227160)博客查看。使用Android stdio编写。
个人整理的Android Intent的使用介绍 Android 组件之间的信使Intent Android 中的数据存取和ContentProvider
前言 在sendBroadcast,startActivity时,我们会用到Intent。 Intent可以携带一些数据,比如基本类型数据int、Boolean,或是String,或是序列化...在Intent中传入一个Parcelable对象;例如传入一个bitmap对象。 代
Android使用Intent和Intentfilter进行通信,源于《疯狂Android讲义》值得学习
android 利用intent调用activity 简明精炼的例子 传递数据,并且有返回值
Android+Intent机制实例详解.rar,详细的介绍了,android中的intent知识,可以下载下来看看哟
Android7.0 Intent打开文件管理器 获取文件真实路径。虽然网上很多demo,但是没有一个能够兼容所有Android机的,去网上学习了然后自己亲测过手机分别有Android7.0/6.0/4.3个版本。