草庐IT

declarative-services

全部标签

java - 为什么我们需要使用 Context.obtainStyledAttributes 和 declare-styleable 来获取 GUI 组件的属性

我刚刚看到一些教程代码示例,它们在XML中使用declare-styleable并在Java代码中使用Context.obtainStyledAttributes。我的理解是,它试图获取GUI组件的属性(如背景颜色)。我在想,为什么我们为了获得一个简单的属性就需要经过这些繁琐的步骤呢?如果我想每次都检索GUI组件属性,我必须创建一个新的XML文件,并将我要检索的属性添加到XML文件本身。我们可以有更简单的东西吗?目前,这是我在尝试获取GUI组件的属性时需要做的事情。http://developer.android.com/resources/tutorials/views/hello-

安卓开发 : Changing Screen Brightness in Service

现在我再试一次。我想改变屏幕亮度。我试过:WindowManager.LayoutParamslayoutParams=getWindow().getAttributes();layoutParams.screenBrightness=0.5F;//set50%brightnessgetWindow().setAttributes(layoutParams);并且似乎在Activity中工作,但是当我在服务中时,我得到了getWindow()编译错误。 最佳答案 服务不能那样改变屏幕亮度。服务没有用户界面,所以它没有Window。您

android - Service.onStartCommand() - 是否可以返回一个以上的标志?

我必须确保我的Service会运行,直到我显式调用stopService()。所以我应该从onStartCommand()返回START_STICKY标志。我还希望万一我的服务因为内存不足而被系统破坏,当系统重新创建它时-onStartCommand()将以最初启动服务的相同Intent被调用。因为这个原因-我想使用START_FLAG_REDELIVERY标志。根据文档-http://developer.android.com/reference/android/app/Service.html#ProcessLifecycle,我所描述的肯定会发生(并且实际上发生在我身上)我知道我

android - 语音识别器 : not connected to recognition service

在我的应用中,我直接使用SpeechRecognizer。我销毁了Activity的SpeechRecognizeronPause并在onResume方法中重新创建它,如下所示...publicclassNoUISpeechActivityextendsActivity{protectedstaticfinalStringCLASS_TAG="NoUISpeechActivity";privateSpeechRecognizersr;@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedIns

java - GC 优化 : declaring object as field opposed to declaring it locally

我目前正试图避免GC_CONCURRENT调用,所以我正在运行我的主循环。我注意到我经常创建一个复杂的对象来进行计算。所以我的问题是将该对象声明为类的一个字段而不是在使用它的方法中声明它有助于提高性能吗?或者因为我的英语可能伤害了你的大脑,这里是代码示例作为字段classmyclass{privateMyObjectmyObject;...publicvoidmyLoopedMethod(...){myObject=newMyObject(...);myObject.dostuff;}方法示例classmyclass{...publicvoidmyLoopedMethod(...){M

android - getLayoutInflator 和 (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE) 有什么区别

我对这两种说法感到困惑。它们有什么区别,我什么时候可以使用它们?LayoutInflaterinflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);Viewv=inflater.inflate(R.layout.activity_custom_lists1,parent);和Viewv=getLayoutInflater().inflater.inflate(R.layout.activity_custom_lists1,parent); 最佳答案

并行运行的 Android Intent Service 工作请求

我创建了一个IntentService如下:publicclassOrdersSyncServiceextendsIntentService{privatestaticfinalStringTAG=OrdersSyncService.class.getSimpleName();privateOrderorderObject;publicOrdersSyncService(){super("OrdersSyncService");}@OverrideprotectedvoidonHandleIntent(Intentintent){//Util.showToast(getApplicat

android - 使用 Android Service Backup (Cloud Backup) 时出现 Unclear SecurityException

我尝试使用我的应用程序,其中包含AndroidBackupService的用法在AndroidEmulator上使用我自己的BackupAgent。但是备份不起作用,尽管在​​AndroidManifest.xml中写入了许可。权限:日志中的警告:09-1709:05:58.553:WARN/PackageManager(73):未授予android.permission.BACKUP打包my.package的权限(protectionLevel=3flags=0x1be46)日志异常(当我尝试调用requestRestore()时):java.lang.SecurityExcepti

android - Google+ 登录 : Google Play Services out of date exception

我正在尝试将GooglePlus登录集成到我的Android应用程序中。当我尝试在AndroidGoogleAPI模拟器上运行此应用程序时,出现一个对话框提示我更新“GooglePlay服务”。单击“更新”按钮时没有任何反应,我可以在logcat中看到以下错误:Can'tredirecttoappsettingsforGooglePlayservices我还在logcat中收到以下警告:GooglePlayservicesoutofdate.Requires3225100butfound3158130另外我想补充一点,我已将GooglePlay服务从修订版8更新到修订版10。谁能告诉我

android - 初始化.rc : invalid service name

尝试在Android上通过init.rc启动服务。servicename_of_my_service/path/to/my/serviceuserroot出现以下错误:init:Invalidservicenamename_of_my_service 最佳答案 您的服务名称太长(或包含无效字符)。服务名称的长度最多为16个字符,并且可以包含字母数字字符、“_”和“-”。https://android.googlesource.com/platform/system/core/+/android-4.2.2_r1.2/init/ini