2024年4月11日发(作者:)

android面试题(2)

Intent intent = new Intent(this,);

gs(_ACTIVITY_CLEAR_TOP);

局限性 :所有的activity的启动模式都要是默认的启动模式

讲一讲你对activity的理解

把上面的几点用自己的心得写出来

8. service是否在main thread中执行, service里面是否能执行

耗时的操作?

默认情况,如果没有显示的指定service所运行的进程, Service和

activity是运行在当前app所在进程的main thread(UI主线程)里面

service里面不能执行耗时的操作(网络请求,拷贝数据库,大文件 )

在子线程中执行 new Thread(){}.start();

特殊情况 ,可以在清单文件配置 service 执行所在的进程 ,让

service在另外的进程中执行

9. 两个Activity之间怎么传递数据?

基本数据类型可以通过. Intent 传递数据

ble(key, value)

ra(name, value)

// 通过intent putExtra 方法 基本数据类型 都传递

Bundle bundle = new Bundle();

rt(key, value);

ras(bundle);

ras(bundle)

获取到激活他的 getIntent();

Intent intent = getIntent();

Bundle bundle = ras();

ingExtra("key","value");

leanExtra("key","value")

Application 全局里面存放 对象 ,自己去实现自己的application

的这个类,基础系统的application , 每个activity都可以取到

让对象实现 implements Serializable 接口把对象存放到文件上.

让类实现Serializable 接口,然后可以通过 ObjectOutputStream

//对象输出流

File file = new File("c:");

FileOutputStream fos = new FileOutputStream(file);

ObjectOutputStream oos = new ObjectOutputStream(fos);

Student stu = new Student();

("10001");

e("zs");

bject(stu);

FileInputStream fis = new FileInputStream(file);

ObjectInputStream ois = new ObjectInputStream(fis);

Student stu1 = (Student) ject();

n(e());

Parcelable 和 Serializable

Parcelable 把对象序列化到android操作系统 的一块公用的内存

空间

文件/网络

a(Uri)

le(); //大图片的传递

utStream(url);

10. 怎么让在启动一个Activity是就启动一个service?

在activity的onCreate()方法里面 startService();

11. 同一个程序,但不同的Activity是否可以放在不同的Task任

务栈中?

比方说在激活一个新的activity时候, 给intent设置flag

Intent的flag添加FLAG_ACTIVITY_NEW_TASK

这个被激活的activity就会在新的task栈里面…

Intent intent = new Intent(,);