??xml version="1.0" encoding="utf-8" standalone="yes"?>
]]>
]]>
<package name="com.android.setupwizard" codePath="/system/app/SetupWizard.apk" nativeLibraryPath="/data/data/com.android.setupwizard/lib" flags="1" ft="13349457a90" it="13349457a90" ut="13349457a90" version="130" userId="10016">
<sigs count="1">
<cert index="0" />
</sigs>
<disabled-components>
<item name="com.android.setupwizard.SetupWizardActivity" />
</disabled-components>
</package>
现在需要在q行时禁用某个widgetQ同时有一个system property用来标识是否需要禁用?br />因ؓwidget实际上就是个reveiverQ它接收android.appwidget.action.APPWIDGET_UPDATE的actionQ所以开始的思\是:
创徏一个BroadcastReceiverQ接收Intent.ACTION_BOOT_COMPLETEDq个动作Q从而在启动完成后调用SystemProperties.get("disable_widget")Q如果需要禁用这个widgetQ那么调用:
PackageManager.setComponentEnabledSetting(widgetComponentNameQPackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
但是问题是,调用q个Ҏ(gu)disable掉这个widget后,发现必须把设备重启之后才能生?..
l过googleQ发现问题出在com.android.server.AppWidgetService.java?br />原来开机后QSystemServer会调用AppWidgetService的systemReady()Ҏ(gu)Q这个方法通过PackageManager查询所有的widget receiverlgQ保存到mInstalledProviders变量列表中,q持久化widget信息?data/system/appwidgets.xml中?br />而在Launcher上长按添加widget时的那个widget列表信息也是通过AppWidgetService取得mInstalledProviders列表?br />问题在于我们通过PackageManager.setComponentEnabledSettingQ)用掉某个widget后,packagemanager实这个组件disable了,但是AppWidgetService却没有去从packagemanager reload widget信息Q这导致了mInstalledProviders中保存的widget信息q是开机时loadq来的那些信息,q没有与pmq行同步。直C一ơ开用systemReady重新加蝲widget信息才会hq个列表?br />
参考:
Dynamically enabling or disabling a widget with PackageManager.setComponentEnabledSetting does not work
http://code.google.com/p/android/issues/detail?id=6533
http://blog.csdn.net/yinlijun2004/article/details/6136108
]]>
2 {
3 int ret = -EBADF;
4 struct file * file = fget(fildes);
5
6 if (file)
7 ret = dupfd(file, 0);
8 return ret;
9 }
10
而sys_dup()的主体是dupfd()Q定义在同一个文件中Q:
2 {
3 struct files_struct * files = current->files;
4 int ret;
5
6 ret = locate_fd(files, file, start);
7 if (ret < 0)
8 goto out_putf;
9 allocate_fd(files, file, ret);
10 return ret;
11
12 out_putf:
13 write_unlock(&files->file_lock);
14 fput(file);
15 return ret;
16 }
17
注:dup和dup2的原型如下:
#include <unistd.h>
int dup(int file_descriptor);
int dup2(int file_descriptor1, int file_descriptor2)
dupq回的文件描q符L取最的可用?br />dup2q回的文件描q符或者与file_descriptor2相同Q或者是W一个大于该参数的可用倹{?/font>
而这么一个简单的pȝ调用是如何完成重定向q个艰巨的Q务的呢?我们不妨先看个例子?br />
当我们在shell下输入如下命令:“echo
hello!”,q条命o要求shellq程执行一个可执行文gechoQ参Cؓ“hello!”。当shell接收到命令之后,先找?
bin/echoQ然后fork()Z个子q程让他执行bin/echoQƈ参C递给它,而这个进E从shelll承了三个标准文Ӟx准输?
QstdinQ,标准输出QstdoutQ和标准出错信息QstderrQ,他们三个的文件号分别????/font>而至于echoq程的工作很单,是参数“hello!”写到标准输出文件中去,通常都是我们的显C器上。但是如果我们将命oҎ(gu)“echo hello! >
foo”,则在执行时输出将会被重定向到盘文gfoo?font color="#0000FF">Q注Q重定向于文件描q符有关Q?/font>。我们假定在此之前该shellq程只有三个标准文g打开Q文件号分别???Q以上命令行按如下序列执行Q?br /> (1) 打开或创建磁盘文件fooQ如果foo中原来有内容Q则清除原来内容Q其文g号ؓ3?br /> (2) 通过dup()复制文gstdoutQ即文件号1出的filel构指针复制到文件号4处,目的是将stdout的file指针暂时保存一?br /> (3) 关闭stdoutQ即1hӞ但是׃4h件对stdout也同时有个引用,所以stdout文gq未真正关闭Q只是腾?h件号位置?br /> (4) 通过dup()Q复?hӞ即磁盘文件fooQ,׃1h件关闭,其位|空~,?h件被复制?P卌E中原来指向stdout的指针指向了foo?br />
(5)
通过pȝ调用fork()和exec()创徏子进Eƈ执行echoQ子q程在执行echo前夕关闭3号和4hӞ只留???三个文gQ请注意Q这
时的1h件已l不是stdout而是盘文gfoo了。当echo惛_stdout文g写入“hello!”时自然写入到了foo中?br /> (6) 回到shell后,关闭指向foo?号与3h件文Ӟ再用dup()和close()?h复至stdoutQ这样shell恢复了0??三个标准输入/输出文g?br />
由此可见Q?font color="#FF0000">当echoE序Q或其他Q在q行的时候ƈ不知道stdoutQ对于stdin和stderr同样Q指向什么,q程与实际输出文件或讑֤的结合是在运行时由其父进E“包办”的。这样就化了子进E的E序设计Q因为在设计时只要跟三个逻辑上存在的文g打交道就可以?/font>。可能有Z觉得q很像面向对象中
的多态和重蝲Q没有什么新奇之处,但是如果你活?0甚至40q前Q可能你会改变你的看法。?
]]>
Activity的生命周期里q没有提到onSaveInstanceState的触发,q个函数提供了ؓ我们在某些情况下保存Activity信息的机会,但需要注意的是这个函C是什么时候都会被调用的,官方文解释的比较清楚,Ҏ(gu)
译一下?
原文出处Qandroid-sdk-windows-1.5_r3/docs/reference/android/app/Activity.html#onSaveInstanceState(android.os.Bundle)
protected void onSaveInstanceState (Bundle outState)
Called to retrieve per-instance state from an activity before
being killed so that the state can be restored in onCreate(Bundle) or
onRestoreInstanceState(Bundle) (the Bundle populated by this method will
be passed to both). This method is called before an activity may be
killed so that when it comes back some time in the future it can restore
its state. For example, if activity B is launched in front of activity
A, and at some point activity A is killed to reclaim resources, activity
A will have a chance to save the current state of its user interface
via this method so that when the user returns to activity A, the state
of the user interface can be restored via onCreate(Bundle) or
onRestoreInstanceState(Bundle).
在activity被杀掉之前调用保存每个实例的状?以保证该状态可以在onCreate(Bundle)或?
onRestoreInstanceState(Bundle)
(传入的Bundle参数是由onSaveInstanceState装好的)中恢复。这个方法在一个activity被杀d调用Q当?
activity在将来某个时d来时可以恢复其先前状态。例如,如果activity B启用后位于activity
A的前端,在某个时刻activity
A因ؓpȝ回收资源的问题要被杀掉,A通过onSaveInstanceState有Z保存其用L面状态,使得来用户q回到activity
A时能通过onCreate(Bundle)或者onRestoreInstanceState(Bundle)恢复界面的状态?
Do not confuse this method with activity lifecycle callbacks
such as onPause(), which is always called when an activity is being
placed in the background or on its way to destruction, or onStop() which
is called before destruction. One example of when onPause() and
onStop() is called and not this method is when a user navigates back
from activity B to activity A: there is no need to call
onSaveInstanceState(Bundle) on B because that particular instance will
never be restored, so the system avoids calling it. An example when
onPause() is called and not onSaveInstanceState(Bundle) is when activity
B is launched in front of activity A: the system may avoid calling
onSaveInstanceState(Bundle) on activity A if it isn't killed during the
lifetime of B since the state of the user interface of A will stay
intact.
不要这个方法和activity生命周期回调如onPause()或onStop()搞淆了QonPause()在activtiy被放|到背景或?
自行销毁时M被调用,onStop()在activity被销毁时被调用。一个会调用onPause()和onStop()Q但不触?
onSaveInstanceState的例子是当用户从activity Bq回到activity
AӞ没有必要调用B的onSaveInstanceState(Bundle)Q此时的B实例永远不会被恢复,因此pȝ会避免调用它。一个调?
onPause()但不调用onSaveInstanceState的例子是当activity B启动q处在activity
A的前端:如果在B的整个生命周期里A的用L面状态都没有被破坏的话,pȝ是不会调用activity
A的onSaveInstanceState(Bundle)的?
The default implementation takes care of most of the UI
per-instance state for you by calling onSaveInstanceState() on each view
in the hierarchy that has an id, and by saving the id of the currently
focused view (all of which is restored by the default implementation of
onRestoreInstanceState(Bundle)). If you override this method to save
additional information not captured by each individual view, you will
likely want to call through to the default implementation, otherwise be
prepared to save all of the state of each view yourself. If called, this
method will occur before onStop(). There are no guarantees about
whether it will occur before or after onPause().
默认的实现负责了大部分UI实例状?的保?Q采用的方式是调用UI层上每个拥有id的view的onSaveInstanceState()
Qƈ且保存当前获得焦点的view的id(所有保存的状态信息都会在默认的onRestoreInstanceState(Bundle)实现中恢??
如果你覆写这个方法来保存额外的没有被各个view保存的信息,你可能想要在默认实现q程中调用或者自׃存每个视囄所有状态。如果被调用Q这个方法会
在onStop()前被触发Q但pȝq不保证是否在onPause()之前或者之后触发?
很多不明白ActivitycM包含的onSaveInstanceState和onRestoreInstanceState有什么用Q首先声
明下使用q两个方法时一定要注意情况和了解Activity的生命周期,否则有的时候?
onSaveInstanceState和onRestoreInstanceState
可能不会被触发,虽然他们都是Activity的重写方法。(?Android开发网Q?
他们比较常用到的地方?
Sensor、Land和Port布局的自动切换,q去Android开发网曄说过解决横屏和竖屏切换带来的数据被置I或者说onCreate被重复调
用问题,其实Android提供的onSaveInstanceStateҎ(gu)可以保存当前的窗口状态在卛_布局切换前或当前Activity被推入历?
栈,其实布局切换也调用过onPause所以被推入Activity的history
stackQ如果我们的Activity在后台没有因行内存吃紧被清理Q则切换回时会触发onRestoreInstanceStateҎ(gu)?
q两个方法中参数均ؓBundleQ可以存攄?SharedPreferences 的数据,所以用它们作为当前窗口的状态保存是比较合适的。实际用代?
@Override
protected void onSaveInstanceState(Bundle outState){
outState.putString("lastPath", "/sdcard/android123/cwj/test");
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
String cwjString = savedInstanceState.getString("lastPath");
}
onSaveInstanceState和onRestoreInstanceState触发的时?
已有 199 ơ阅?2011-3-10 10:32 |个h分类:Android|关键?onSaveInstanceState onRestoreInstanceState
先看Application Fundamentals上的一D话Q?
Android calls onSaveInstanceState() before the activity becomes
vulnerable to being destroyed by the system, but does not bother calling
it when the instance is actually being destroyed by a user action (such
as pressing the BACK key)
从这句话可以知道Q当某个activity变得“容易”被pȝ销毁时Q该activity的onSaveInstanceState׃被执行,除非该activity是被用户d销毁的Q例如当用户按BACK键的时候?
注意上面的双引号Q何为“容易”?a下之意就是该activityq没有被销毁,而仅仅是一U可能性。这U可能性有哪些Q通过重写一?
activity的所有生命周期的onXXXҎ(gu)Q包括onSaveInstanceState和onRestoreInstanceStateҎ(gu)Q我
们可以清楚地知道当某个activityQ假定ؓactivity
AQ显C在当前task的最上层Ӟ其onSaveInstanceStateҎ(gu)会在什么时候被执行Q有q么几种情况Q?
1、当用户按下HOME键时。这是显而易见的Q系l不知道你按下HOME后要q行多少其他的程序,自然也不知道activity A是否会被销毁,故系l会调用onSaveInstanceStateQ让用户有机会保存某些非怹性的数据。以下几U情늚分析都遵循该原则
2、长按HOME键,选择q行其他的程序时?
3、按下电(sh)源按键(关闭屏幕昄Q时?
4、从activity A中启动一个新的activity时?
5、屏q方向切换时Q例如从竖屏切换到横屏时。在屏幕切换之前Q系l会销毁activity AQ在屏幕切换之后pȝ又会自动地创建activity AQ所以onSaveInstanceState一定会被执?
总而言之,onSaveInstanceState的调用遵循一个重要原则,卛_pȝ“未l你许可”时销毁了你的activityQ则
onSaveInstanceState会被pȝ调用Q这是系l的责QQ因为它必须要提供一个机会让你保存你的数据(当然你不保存那就随便你了Q?
至于onRestoreInstanceStateҎ(gu)Q需要注意的是,onSaveInstanceStateҎ(gu)?
onRestoreInstanceStateҎ(gu)“不一定”是成对的被调用的,onRestoreInstanceState被调用的前提
是,activity A“确实”被pȝ销毁了Q而如果仅仅是停留在有q种可能性的情况下,则该Ҏ(gu)不会被调用,例如Q当正在昄activity
A的时候,用户按下HOME键回C界面Q然后用L接着又返回到activity AQ这U情况下activity
A一般不会因为内存的原因被系l销毁,故activity A的onRestoreInstanceStateҎ(gu)不会被执?
另外QonRestoreInstanceState的bundle参数也会传递到onCreateҎ(gu)中,你也可以选择在onCreateҎ(gu)中做数据q原
]]>
看文:
Returns an estimated number of bytes that can be read or skipped without blocking for more input.
Note that this method provides such a weak guarantee that it is not very useful in practice.
Firstly, the guarantee is "without blocking for more input" rather than "without blocking": a read may still block waiting for I/O to complete ?the guarantee is merely that it won't have to wait indefinitely for data to be written. The result of this method should not be used as a license to do I/O on a thread that shouldn't be blocked.
Secondly, the result is a conservative estimate and may be significantly smaller than the actual number of bytes available. In particular, an implementation that always returns 0 would be correct. In general, callers should only use this method if they'd be satisfied with treating the result as a boolean yes or no answer to the question "is there definitely data ready?".
Thirdly, the fact that a given number of bytes is "available" does not guarantee that a read or skip will actually read or skip that many bytes: they may read or skip fewer.
It is particularly important to realize that you must not use this method to size a container and assume that you can read the entirety of the stream without needing to resize the container. Such callers should probably write everything they read to a ByteArrayOutputStream and convert that to a byte array. Alternatively, if you're reading from a file, length() returns the current length of the file (though assuming the file's length can't change may be incorrect, reading a file is inherently racy).
The default implementation of this method in InputStream always returns 0. Subclasses should override this method if they are able to indicate the number of bytes available.
]]>
1QBIG-ENDIAN、LITTLE-ENDIAN、跟CPU有关的,每一UCPU不是BIG-ENDIAN是LITTLE- ENDIAN、。IA架构的CPU中是Little-EndianQ而PowerPC 、SPARC和Motorola处理器。这其实是所谓的L字节序。而网l字节序是指数据在网l上传输时是大头q是头的,在Internet的网l字 节序是BIG-ENDIAN。所谓的JAVA字节序指的是在JAVA虚拟Z多字节类型数据的存放序QJAVA字节序也是BIG-ENDIAN?/p>
2Q所以在用C/C++写通信E序Ӟ在发送数据前务必用htonl和htonsL整型和短整型的数据进行从L字节序到|络字节序的转换Q而接 收数据后对于整型和短整型数据则必调用ntohl和ntohs实现从网l字节序C机字节序的{换。如果通信的一Ҏ(gu)JAVAE序、一Ҏ(gu)C/C++E? 序时Q则需要在C/C++一侧用以上几个方法进行字节序的{换,而JAVA一侧,则不需要做M处理Q因为JAVA字节序与|络字节序都是BIG- ENDIANQ只要C/C++一侧能正确q行转换卛_Q发送前从主机序到网l序Q接收时反变换)。如果通信的双斚w是JAVAQ则Ҏ(gu)不用考虑字节序的? 题了?/p>
转自http://www.embest.net/index.php/archives/259