当前位置: 编程技术>移动开发
本页文章导读:
▪ActivityManager: java.lang.SecurityException 有关问题 ActivityManager: java.lang.SecurityException 问题
最近在调试程序的时候经常出现ActivityManager: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] .........
▪ 懂得sendStickyBroadcast 理解sendStickyBroadcast
抄录了关于sendStickyBoradcast()的相关理解.关于sendStickyBoradcast(),SDK中的相关说明:引用Perform a sendBroadcast(Intent) that is "sticky," meaning the Intent you are sending stays around after the broad.........
▪ 从资源中获取位图的两种步骤 从资源中获取位图的两种方法
方法(1):先获取Resource,然后可以通过资源ID获取Drawable,也可以通过资源ID获取资源文件的数据流Drawable是个抽象类,在BitmapDrawable中我们就看到位图的具.........
[1]ActivityManager: java.lang.SecurityException 有关问题
来源: 互联网 发布时间: 2014-02-18
ActivityManager: java.lang.SecurityException 问题
最近在调试程序的时候经常出现ActivityManager: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.xxxxx.xxxxx/.ui.xxxxxxx } from null (pid=-1, uid=-1) requires null的问题,困扰我好几天了,一开始只是认为权限的问题,跟了好久一直没有解决。
后来看到:
The java.lang.SecurityException you are seeing is because you may enter two entries pointing to same activity. Remove the second one and you should be good to go.
才发现这个Activity在Manifest文件里写了两份,去掉一份后,终于可以正常运行了。
注:此问题还会引起,在手机端点击程序图标时,会提示程序未安装在手机上。
最近在调试程序的时候经常出现ActivityManager: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.xxxxx.xxxxx/.ui.xxxxxxx } from null (pid=-1, uid=-1) requires null的问题,困扰我好几天了,一开始只是认为权限的问题,跟了好久一直没有解决。
后来看到:
The java.lang.SecurityException you are seeing is because you may enter two entries pointing to same activity. Remove the second one and you should be good to go.
才发现这个Activity在Manifest文件里写了两份,去掉一份后,终于可以正常运行了。
注:此问题还会引起,在手机端点击程序图标时,会提示程序未安装在手机上。
1 楼
Jorson33
2011-10-12
感谢!!!!
[2] 懂得sendStickyBroadcast
来源: 互联网 发布时间: 2014-02-18
理解sendStickyBroadcast
抄录了关于sendStickyBoradcast()的相关理解.
关于sendStickyBoradcast(),SDK中的相关说明:
These are broadcasts whose data is held by the system after being finished, so that clients can quickly retrieve that data without having to wait for the next broadcast.
上面的解释,不是特别好理解, 请看下面的解释.
One example of a sticky broadcast sent via the operating system is ACTION_BATTERY_CHANGED. When you call registerReceiver() for that action -- even with a null BroadcastReceiver -- you get the Intent that was last broadcast for that action. Hence, you can use this to find the state of the battery without necessarily registering for all future state changes in the battery.
Heres an abstract example of how one might use a sticky broadcast:
Intent intent = new Intent("some.custom.action");
intent.putExtra("some_boolean", true);
sendStickyBroadcast(intent);
If you are listening for this broadcast in an Activity that was frozen (onPause), you could miss the actual event. This allows you to check the broadcast after it was fired (onResume).
EDIT: More on sticky boradcasts...
Also check out removeStickyBroadcast(Intent), and on API Level 5 +, isInitialStickyBroadcast() for usage in the Receiver's onReceive.
资料来源:
http://stackoverflow.com/questions/3490913/what-is-a-sticky-intent-android
http://stackoverflow.com/questions/2584497/what-is-the-difference-between-sendstickybroadcast-and-sendbroadcast-in-android
一个小的知识点整理,希望大家有用.
抄录了关于sendStickyBoradcast()的相关理解.
关于sendStickyBoradcast(),SDK中的相关说明:
引用
Perform a sendBroadcast(Intent) that is "sticky," meaning the Intent you are sending stays around after the broadcast is complete, so that others can quickly retrieve that data through the return value of registerReceiver(BroadcastReceiver, IntentFilter). In all other ways, this behaves the same as sendBroadcast(Intent).
引用
These are broadcasts whose data is held by the system after being finished, so that clients can quickly retrieve that data without having to wait for the next broadcast.
上面的解释,不是特别好理解, 请看下面的解释.
One example of a sticky broadcast sent via the operating system is ACTION_BATTERY_CHANGED. When you call registerReceiver() for that action -- even with a null BroadcastReceiver -- you get the Intent that was last broadcast for that action. Hence, you can use this to find the state of the battery without necessarily registering for all future state changes in the battery.
Heres an abstract example of how one might use a sticky broadcast:
Intent intent = new Intent("some.custom.action");
intent.putExtra("some_boolean", true);
sendStickyBroadcast(intent);
If you are listening for this broadcast in an Activity that was frozen (onPause), you could miss the actual event. This allows you to check the broadcast after it was fired (onResume).
EDIT: More on sticky boradcasts...
Also check out removeStickyBroadcast(Intent), and on API Level 5 +, isInitialStickyBroadcast() for usage in the Receiver's onReceive.
资料来源:
http://stackoverflow.com/questions/3490913/what-is-a-sticky-intent-android
http://stackoverflow.com/questions/2584497/what-is-the-difference-between-sendstickybroadcast-and-sendbroadcast-in-android
一个小的知识点整理,希望大家有用.
[3] 从资源中获取位图的两种步骤
来源: 互联网 发布时间: 2014-02-18
从资源中获取位图的两种方法
方法(1):先获取Resource,然后可以通过资源ID获取Drawable,也可以通过资源ID获取资源文件的数据流Drawable是个抽象类,在BitmapDrawable中我们就看到位图的具体操作,在仔细看下BitmapDrawable的构造函数,我们就会发现与Resource中的openRawResource()接口是相对应的,就可以通过以下方法来获取位图:
Resources r = this.getContext().getResources();
Inputstream is = r.openRawResource(R.drawable.my_background_image);
BitmapDrawable bmpDraw = new BitmapDrawable(is);
Bitmap bmp = bmpDraw.getBitmap();
方法(2):通过Resource的函数:InputStream openRawResource(int id)获取得到资源文件的数据流后,也可以通过2种方法来获取Bitmap,如下:
使用BitmapDrawable
(A Drawable that wraps a bitmap and can be tiled, stretched, or aligned.)
使用BitmapDrawable (InputStream is)构造一个BitmapDrawable;使用BitmapDrawable类的getBitmap()获取得到位图;
BitmapDrawable也提供了显示位图等操作
使用BitmapFactory
(Creates Bitmap objects from various sources, including files, streams, and byte-arrays.)
使用BitmapFactory类decodeStream(InputStream is)解码位图资源,获取位图
BitmapFactory的所有函数都是static,这个辅助类可以通过资源ID、路径、文件、数据流等方式来获取位图。
以上方法在编程的时候可以自由选择,在Android SDK中说明可以支持的图片格式如下:png (preferred), jpg (acceptable), gif (discouraged),虽然bmp格式没有明确说明,但是在Android SDK Support Media Format中是明确说明了。
方法(1):先获取Resource,然后可以通过资源ID获取Drawable,也可以通过资源ID获取资源文件的数据流Drawable是个抽象类,在BitmapDrawable中我们就看到位图的具体操作,在仔细看下BitmapDrawable的构造函数,我们就会发现与Resource中的openRawResource()接口是相对应的,就可以通过以下方法来获取位图:
Resources r = this.getContext().getResources();
Inputstream is = r.openRawResource(R.drawable.my_background_image);
BitmapDrawable bmpDraw = new BitmapDrawable(is);
Bitmap bmp = bmpDraw.getBitmap();
方法(2):通过Resource的函数:InputStream openRawResource(int id)获取得到资源文件的数据流后,也可以通过2种方法来获取Bitmap,如下:
使用BitmapDrawable
(A Drawable that wraps a bitmap and can be tiled, stretched, or aligned.)
使用BitmapDrawable (InputStream is)构造一个BitmapDrawable;使用BitmapDrawable类的getBitmap()获取得到位图;
BitmapDrawable也提供了显示位图等操作
使用BitmapFactory
(Creates Bitmap objects from various sources, including files, streams, and byte-arrays.)
使用BitmapFactory类decodeStream(InputStream is)解码位图资源,获取位图
BitmapFactory的所有函数都是static,这个辅助类可以通过资源ID、路径、文件、数据流等方式来获取位图。
以上方法在编程的时候可以自由选择,在Android SDK中说明可以支持的图片格式如下:png (preferred), jpg (acceptable), gif (discouraged),虽然bmp格式没有明确说明,但是在Android SDK Support Media Format中是明确说明了。
1 楼
77095729
2011-09-07
收藏起来 慢慢看
最新技术文章: