学习android之 知识点总结
2015-01-20 15:53
369 查看
开发andorid程序必备:
Eclipse 3.5以上版本
SDK类似于java中的jdk。
Adt 是开发Eclipe上的一个插件。
组件使用:
TestView:
为文本设置超链接,需设置该属性andorid:autoLink=”all”, 具体如下:
<TextView
android:id="@+id/myTxtView01"
android:autoLink="all"
android:text="百度: http://www.baidu.com"/>
组件跳转:
运用改变Activity Layout这个技巧,就可以做出手机界面转换的效果(setContentView())。但这里有一个疑点不大很明白,就是当我定义了两个layout中定义了分别定义了一个用于跳转的Button,当我从一个界面跳转到另一个界面之后,然后再从这个界面跳转到之前界面,再从之前界面跳转的时候,此时按钮是否就需重新注册,这是为是么???
调用另一个Activity:
通过Intent来实现两个Activity间的相互跳转。具体代码如下:
Intent intent = new Intent();
intent.setClass(TwoActivityChangeActivity.this, SecondActivity.class);
startActivity(intent);
TwoActivityChangeActivity.this.finish();
其中还需要在AndroidMainfest.xml中添加要跳转到的Activity, android.intent.category.LAUNCHER是用来设置先运行的Activity。
采用Bundle对象来实现不同Activity之间的数据传递
首先是先new 一个Bundle对象,然后将要传递的类型直接put进去即可。示例代码:
Bundle bundle = new Bundle();
bundle.putDouble(2);
bundle.putString(“yaner”);
intent.putExtras(bundle);
取得数据的时候采用getIntent().getExtras()来获取Bundle。
Handler传递数据
实例化一个handler对象:
Handler handler = new Handler(){
public void handleMessage(Message msg){
super.handleMessage(msg);
Bundle bundle = msg.getData();
String number = bundle.getString("number");
switch(msg.what){
case UPDATE_TIME:
mTextView.setText("正在更新时间:" + number);
break;
case UPDATE_COMPLETED:
mTextView.setText("更新时间完毕");
break;
}
}
};
然后封装数据并发送:
Bundle bandle = new Bundle();
bandle.putString("number", mShowNumber);
Message msg = new Message();
msg.what = UPDATE_TIME;
Msg.setData = “yaner”;
handler.sendMessage(msg);
Notification 发送消息
notification(通知) 使用:
使用通知的一个好处就是在当程序运行的时候,通过调用调用
notification给用户发送一条消息, 这样不会中断用户当前的操作,
不想AlertDialog显示那样,会截获屏幕焦点,
比如,当玩家正在玩游戏的时候,使用notification不会干扰到玩家游戏,
玩家尽可以等玩完游戏之后再去看notification(通知),而如果使用AlertDialog
的话, 则此时玩家将必须关闭AliertDialog之后才能继续玩游戏。
首先得到消息的管理对象
NotificationManager mManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon, "奋斗赚大钱", System.currentTimeMillis());
notification.flags = Notification.FLAG_AUTO_CANCEL;
Intent intent = new Intent(this, MessageAndHandlerAppActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
Bundle bundle = new Bundle();
bundle.putString("name", "从Notification跳转过来的");
intent.putExtras(bundle);
PendingIntent contentIntent = PendingIntent.getActivity(this,
R.string.app_name, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(this, "努力啊", "想法子挣钱", contentIntent);
然后调用mManager.notify(0, notification);即可.
返回数据到前一个Activity 采用startActivityForResult()方法
示例:
第一个activity:
/**实例化一个Intent*/
Intent intent = new Intent();
intent.setClass(TwoActivityChangeActivity.this, SecondActivity.class);
//注意这里在跳转的时候没有销毁intent,我估计销毁的话采用这种方式,就传不过来值了。需作测试。。。。
/**实例化一个用于传输数据的Bundle*/
Bundle bundle = new Bundle();
bundle.putDouble("height", height);
intent.putExtras(bundle);
startActivityForResult(intent, 0);
第二个activity:
SecondActivity.this.setResult(RESULT_OK, intent); //intent是第一个activity传过来的Intent.
SecondActivity.this.finish();
保存数据的几种方式:
1. ShredPreferences临时存取数据
sharedPreferences是以XML的格式以文件的方式自动保存的。
2. 保存到目录文件下。 如:
String filename = “tempfile.tmp”;
FileOutputStream fos = openFileOutput(file_name, Context.MOME_PRIVATE);
3. 采用SQLITE存储
在程序中取得layout,然后在添加相应的视图
setContentView(R.layout.image);
ImageView imgView = new ImageView(this);
LinearLayout ll = (LinearLayout) findViewById(R.id.imageId);
ll.addView(new FrameView(this));
在Activity中获得屏幕宽、高
Display display = getWindwManager().getDefaultDisplay();
display.getWidth(); display.getHeight();
全屏幕窗口设置
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
强制横屏的方法
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANGSCAPE);
强制竖屏的方法
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
保存数据的几种方法:
1. 用sharedPreferences保存到xml文件中
2. 保存到自定义的file文件中
3. 保存到SD卡中
4. 从程序目录下读取数据(这种方式只能读不能写)
Dialog弹出框
Theme主题修改
Toatst对象的使用
Toast mtoast = new Toast(this);
ImageView mview = new ImageView(this);
mview.setImageResource(R.drawable.icon);
mtoast.setView(mview);
mtoast.show();
ImageView图片呈现
Animation动画特效…找个示例看看,主要是xml
另外getSystemService()是Android很重要的一个API,它是Activity的一个方法,根据传入的NAME来取得对应的Object,然后转换成相应的服务对象。以下介绍系统相应的服务。
查看android sdk版本
在sdk中,找到tools里面的android,执行它,然后点击about就能够看到该版本信息
查看签名的文件
keytool -list -keystore "android.keystore" 输入你设置的keystore密码即可
df 查看外接挂载设备
查看是否已经正确签名:
jarsigner -verify -verbose -certs E:\工作\打包工具\test\signedAPK\abc.apk
Eclipse 3.5以上版本
SDK类似于java中的jdk。
Adt 是开发Eclipe上的一个插件。
组件使用:
TestView:
为文本设置超链接,需设置该属性andorid:autoLink=”all”, 具体如下:
<TextView
android:id="@+id/myTxtView01"
android:autoLink="all"
android:text="百度: http://www.baidu.com"/>
组件跳转:
运用改变Activity Layout这个技巧,就可以做出手机界面转换的效果(setContentView())。但这里有一个疑点不大很明白,就是当我定义了两个layout中定义了分别定义了一个用于跳转的Button,当我从一个界面跳转到另一个界面之后,然后再从这个界面跳转到之前界面,再从之前界面跳转的时候,此时按钮是否就需重新注册,这是为是么???
调用另一个Activity:
通过Intent来实现两个Activity间的相互跳转。具体代码如下:
Intent intent = new Intent();
intent.setClass(TwoActivityChangeActivity.this, SecondActivity.class);
startActivity(intent);
TwoActivityChangeActivity.this.finish();
其中还需要在AndroidMainfest.xml中添加要跳转到的Activity, android.intent.category.LAUNCHER是用来设置先运行的Activity。
采用Bundle对象来实现不同Activity之间的数据传递
首先是先new 一个Bundle对象,然后将要传递的类型直接put进去即可。示例代码:
Bundle bundle = new Bundle();
bundle.putDouble(2);
bundle.putString(“yaner”);
intent.putExtras(bundle);
取得数据的时候采用getIntent().getExtras()来获取Bundle。
Handler传递数据
实例化一个handler对象:
Handler handler = new Handler(){
public void handleMessage(Message msg){
super.handleMessage(msg);
Bundle bundle = msg.getData();
String number = bundle.getString("number");
switch(msg.what){
case UPDATE_TIME:
mTextView.setText("正在更新时间:" + number);
break;
case UPDATE_COMPLETED:
mTextView.setText("更新时间完毕");
break;
}
}
};
然后封装数据并发送:
Bundle bandle = new Bundle();
bandle.putString("number", mShowNumber);
Message msg = new Message();
msg.what = UPDATE_TIME;
Msg.setData = “yaner”;
handler.sendMessage(msg);
Notification 发送消息
notification(通知) 使用:
使用通知的一个好处就是在当程序运行的时候,通过调用调用
notification给用户发送一条消息, 这样不会中断用户当前的操作,
不想AlertDialog显示那样,会截获屏幕焦点,
比如,当玩家正在玩游戏的时候,使用notification不会干扰到玩家游戏,
玩家尽可以等玩完游戏之后再去看notification(通知),而如果使用AlertDialog
的话, 则此时玩家将必须关闭AliertDialog之后才能继续玩游戏。
首先得到消息的管理对象
NotificationManager mManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon, "奋斗赚大钱", System.currentTimeMillis());
notification.flags = Notification.FLAG_AUTO_CANCEL;
Intent intent = new Intent(this, MessageAndHandlerAppActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
Bundle bundle = new Bundle();
bundle.putString("name", "从Notification跳转过来的");
intent.putExtras(bundle);
PendingIntent contentIntent = PendingIntent.getActivity(this,
R.string.app_name, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(this, "努力啊", "想法子挣钱", contentIntent);
然后调用mManager.notify(0, notification);即可.
返回数据到前一个Activity 采用startActivityForResult()方法
示例:
第一个activity:
/**实例化一个Intent*/
Intent intent = new Intent();
intent.setClass(TwoActivityChangeActivity.this, SecondActivity.class);
//注意这里在跳转的时候没有销毁intent,我估计销毁的话采用这种方式,就传不过来值了。需作测试。。。。
/**实例化一个用于传输数据的Bundle*/
Bundle bundle = new Bundle();
bundle.putDouble("height", height);
intent.putExtras(bundle);
startActivityForResult(intent, 0);
第二个activity:
SecondActivity.this.setResult(RESULT_OK, intent); //intent是第一个activity传过来的Intent.
SecondActivity.this.finish();
保存数据的几种方式:
1. ShredPreferences临时存取数据
sharedPreferences是以XML的格式以文件的方式自动保存的。
2. 保存到目录文件下。 如:
String filename = “tempfile.tmp”;
FileOutputStream fos = openFileOutput(file_name, Context.MOME_PRIVATE);
3. 采用SQLITE存储
在程序中取得layout,然后在添加相应的视图
setContentView(R.layout.image);
ImageView imgView = new ImageView(this);
LinearLayout ll = (LinearLayout) findViewById(R.id.imageId);
ll.addView(new FrameView(this));
在Activity中获得屏幕宽、高
Display display = getWindwManager().getDefaultDisplay();
display.getWidth(); display.getHeight();
全屏幕窗口设置
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
强制横屏的方法
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANGSCAPE);
强制竖屏的方法
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
保存数据的几种方法:
1. 用sharedPreferences保存到xml文件中
2. 保存到自定义的file文件中
3. 保存到SD卡中
4. 从程序目录下读取数据(这种方式只能读不能写)
Dialog弹出框
Theme主题修改
Toatst对象的使用
Toast mtoast = new Toast(this);
ImageView mview = new ImageView(this);
mview.setImageResource(R.drawable.icon);
mtoast.setView(mview);
mtoast.show();
ImageView图片呈现
Animation动画特效…找个示例看看,主要是xml
另外getSystemService()是Android很重要的一个API,它是Activity的一个方法,根据传入的NAME来取得对应的Object,然后转换成相应的服务对象。以下介绍系统相应的服务。
传入的Name | 返回的对象 | 说明 |
WINDOW_SERVICE | WindowManager | 管理打开的窗口程序 |
LAYOUT_INFLATER_SERVICE | LayoutInflater | 取得xml里定义的view |
ACTIVITY_SERVICE | ActivityManager | 管理应用程序的系统状态 |
POWER_SERVICE | PowerManger | 电源的服务 |
ALARM_SERVICE | AlarmManager | 闹钟的服务 |
NOTIFICATION_SERVICE | NotificationManager | 状态栏的服务 |
KEYGUARD_SERVICE | KeyguardManager | 键盘锁的服务 |
LOCATION_SERVICE | LocationManager | 位置的服务,如GPS |
SEARCH_SERVICE | SearchManager | 搜索的服务 |
VEBRATOR_SERVICE | Vebrator | 手机震动的服务 |
CONNECTIVITY_SERVICE | Connectivity | 网络连接的服务 |
WIFI_SERVICE | WifiManager | Wi-Fi服务 |
TELEPHONY_SERVICE | TeleponyManager | 电话服务 |
在sdk中,找到tools里面的android,执行它,然后点击about就能够看到该版本信息
查看签名的文件
keytool -list -keystore "android.keystore" 输入你设置的keystore密码即可
df 查看外接挂载设备
查看是否已经正确签名:
jarsigner -verify -verbose -certs E:\工作\打包工具\test\signedAPK\abc.apk
相关文章推荐
- Android学习日志之二:Activity知识点总结
- android 学习知识点总结
- android学习:知识点总结
- 第一次写自己的blog,第一次把android的学习的各个知识点总结并增加自己学习的DEMO
- Android知识点总结,学习过程梳理
- Android阶段学习总结 7.25-7.29 天气预报 知识点
- 快速学习Android开发知识点总结(磨砺营马剑威Android)
- 【android学习】android知识点总结
- Android画图学习总结(四)——Animation(上)
- 传智播客学习之面试知识点总结-标签
- 传智播客学习之面试知识点总结struts
- Android画图学习总结(四)——Animation(下)
- Android画图学习总结(一)——类的简介
- Android画图学习总结(三)——Drawable
- android学习总结
- Android画图学习总结(五)——Paint
- gps和android service和pseudo terminal学习总结
- Android画图学习总结(四)——Animation(下)
- Android画图学习总结(二)——Bitmap
- Android画图学习总结(二)——Bitmap