Head Fisrt Android Development读书笔记(3)When things take time

本文介绍了Android应用程序的生命周期状态转换,包括onCreate(), onStart() 和 onResume()等关键方法的作用。此外还探讨了如何有效管理Android UI线程以确保良好的用户体验,以及一些常用的布局属性设置。

The activity lifecycle

onCreate() : called when your activity is created and typically where layouts and configuration occurs -->

onStart(): called when your activity is displayed on the screen. -->

onResume()\onPause(): this could be caused by a phone call, an alert from another application, or a user switching to a different app.

Auto-refresh mechanism is processor and battery intensive. (How sensitive???)

android:gravity="center"

android:padding="5dp" controls the spaceing between views within a layout

android:layout_marginTop="5dp" controls the spacing between this view and the views outside this layout.

android:backgroud="#FF8D8D8D"

android:layout_height="wrap_content": just as big bas it needs to be

android:layout_hegiht="fill_parent". fill all of the space it can

android:layout_weight="1" make the view stretch, "0" make that view just as big as needed.


ProgressDialog

show a dialog:

ProgressDialog dialog = ProgressDialog.show(this, "Loading", "Loading the image og the Day");

dismiss the dialog

dialog.dismiss();

Dedicated UI thread

Android has a dedicated thread for updating the UI, it it responsible for prepaints, layouts, and other graphical processing that helps keep the UI responsive and keeps animation smooth. The UI has a queue of work, and it continually gets the most important chunk of work to process.

1.KEEPthe UI threadFREE of expensive processing for a responsive UI.

2.Make SURE all necessary UI code occurs on the UI thread.

Handler

handler works by keeping a reference to the thread it was created by. You can pass it work and Handler ensures that the code is executed on the insatntiated thread.

Handler handler;

public void onCreat(...)

{

...

handler = new Handler();

refreshFromFeed();

}

pass work to the Handler using post

handler.post(Runnable runnable)


WallpaperManager

WallpaperManager wallpaperManager = WallpaperManager.getInstance(NasaDailyImage.this);

wallpaperManager.setBitmap(image);

Toast

Toast.makeText(NasaDailyImage.this, "Wallpaper set", Toast.LENGTH_SHORT).show();

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值