【Android进阶】Android面试题目整理与讲解(一)
这一篇文章专门整理一下研究过的Android面试题,内容会随着学习不断的增加,如果答案有错误,希望大家可以指正
1.简述Activity的生命周期
2.Intent启动Activity有几种方式,如何实现?
Intent intent = new Intent(this,OtherActivity.class);
startActivity(intent);
显式意图还有另外一种形式
Intent intent = new Intent();
ComponentName component = new ComponentName(this, OtherActivity.class);
intent.setComponent(component);
startActivity(intent);
其实这两种形式其实是一样的,我们看一下Intent构造函数的代码
public Intent(Context packageContext, Class<?> cls) {
mComponent = new ComponentName(packageContext, cls);
}
这样我们就一目了然了,其实我们经常使用的Intent的构造方法是第二种方式的简化版
Intent intent = new Intent();
intent.setAction("other");
startActivity(intent);
隐式意图是通过setAction来进行区分到底跳转到哪一个界面,那么我们肯定要在需要跳转的页面设置一标志,我们需要在AndroidManifest.xml中对这个进行设置
<activity android:name="com.example.lifecicledemo.OtherActivity" >
<intent-filter>
<action android:name="other" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
这样当我们使用setAction的时候,就可以知道我们到底是想跳转到哪一个页面了。
3.Android中获取图片有哪几种方式
Drawable drawable = getResources().getDrawable(R.drawable.ic_launcher);
img.setImageDrawable(drawable);
方式二
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_launcher);
img.setImageBitmap(bitmap);
方式三
AssetManager assetManager = getResources().getAssets();
try {
InputStream is = assetManager.open("ic_launcher.png");
Bitmap bitmap = BitmapFactory.decodeStream(is);
img.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
方式四
AssetManager assetManager = getResources().getAssets();
try {
InputStream is = assetManager.open("ic_launcher.png");
Drawable drawable = Drawable.createFromStream(is, null);
img.setImageDrawable(drawable);
} catch (IOException e) {
e.printStackTrace();
}
【Android进阶】Android面试题目整理与讲解(一)的更多相关文章
- 【Android进阶】Android面试题目整理与讲解(二)
1. ArrayList,Vector, LinkedList 的存储性能和特性 ArrayList 和 Vector 都是使用数组方式存储数据,此数组元素数大于实际存储的数据以便增加和插入元素,它们 ...
- Android面试题目整理与解说(一)
这一篇文章专门整理一下研究过的Android面试题,内容会随着学习不断的添加,假设答案有错误,希望大家能够指正 1.简述Activity的生命周期 当Activity開始启动的时候,首先调用onCre ...
- Android面试题目整理与解说(二)
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/bz419927089/article/details/31386787 1.Dalvik和标准Jav ...
- Android 进阶 Android 中的 IOC 框架 【ViewInject】 (下)
上一篇博客我们已经带大家简单的吹了一下IoC,实现了Activity中View的布局以及控件的注入,如果你不了解,请参考:Android 进阶 教你打造 Android 中的 IOC 框架 [View ...
- Android进阶——Android事件分发机制之dispatchTouchEvent、onInterceptTouchEvent、onTouchEvent
Android事件分发机制可以说是我们Android工程师面试题中的必考题,弄懂它的原理是我们避不开的任务,所以长痛不如短痛,花点时间干掉他,废话不多说,开车啦 Android事件分发机制的发生在Vi ...
- C++常见的面试题目整理
本文列出C++面试中经常遇到的一些问题,都是一些常见的面试考点,如果后续遇到其他常见面试问题还会再次更新.希望对近期参加面试的同学有一些帮助.先后顺序与问题的重要性无关,查看的时候,最好是全面了解一下 ...
- Android 进阶Android 中的 IOC 框架 【ViewInject】 (上)
1.概述 首先我们来吹吹牛,什么叫IoC,控制反转(Inversion of Control,英文缩写为IoC),什么意思呢? 就是你一个类里面需要用到很多个成员变量,传统的写法,你要用这些成员变量, ...
- ES6高频面试题目整理
本篇文章是根据以下内容进行的总结 1.https://segmentfault.com/a/1190000011344301 2.http://www.bslxx.com/a/mianshiti/ti ...
- Android进阶——Android视图工作机制之measure、layout、draw
自定义View一直是初学者们最头疼的事情,因为他们并没有了解到真正的实现原理就开始试着做自定义View,碰到很多看不懂的代码只能选择回避,做多了会觉得很没自信.其实只要了解了View的工作机制后,会发 ...
随机推荐
- 引用类中的enum
引用类中的enum 引用类中的enum,需要加类的域class_name::value_in_enum_name 点击(此处)折叠或打开 #include <stdio.h> #inclu ...
- Automatic logon configuration on Linux OS
Automatic logon configuration on Linux OS 1. Regarding to DSA: a) ssh-keygen -t dsa b) cat ~/.ssh/i ...
- 【夯实基础】Spring在ssh中的作用
尊重版权:http://blog.csdn.net/qjlsharp/archive/2009/03/21/4013255.aspx 写的真不错. 在SSH框假中spring充当了管理容器的角色.我们 ...
- delphi cmd(4个例子都是通过管道取得)
//K8执行DOS并返回结果 function RunDosCommand(Command: string): string; var hReadPipe: THandle; hWritePipe: ...
- [Android学习笔记]捕获物理回退事件
物理回退按钮默认情况下是finish当前activity,返回上一个activity 当需要获取物理回退按钮的相应事件时候,可以这么做 步骤如下: 1.override当前activity的onKey ...
- OCP读书笔记(16) - 管理资源
使用者组 创建资源用户组OLTP_GRP,将用户HR,OE加入此组: BEGIN dbms_resource_manager.clear_pending_area(); dbms_resource_m ...
- 高效合并两个有序数组(Merge Sorted Array)
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: Y ...
- jQuery选择器实现隔行变色和使用javaScript实现隔行变色
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <!--什么是选择器? jQuery选择器继承了 ...
- wpf dll和exe合并成一个新的exe
原文:wpf dll和exe合并成一个新的exe 微软有一个工具叫ILMerge可以合并dll exe等,但是对于wpf的应用程序而言这个工具就不好用了.我的这方法也是从国外一个博客上找来的.仅供大家 ...
- A Game of Thrones(15) - Sansa
Eddard Stark had left before dawn, Septa Mordane informed Sansa as they broke their fast. “The king ...