草庐IT

context-notes-zh-cn

全部标签

android - 方法 checkSelfPermission(Context, String) 未定义类型 ContextCompat

Contextcontext;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Contextcontext=(Permission)this;//Inanactualapp,you'dwanttorequestapermissionwhentheuser//performsanaction//thatrequiresthatpermission.if(Build.VERSIO

android - 执行 createChooser(context,intent,IntentSender) 后不调用 BroadcastReceiver

我想检测用户在我向他展示createChooser()对话框后选择的应用程序。所以我创建了我的BroadcastReceiver子类,如下所示:importandroid.content.BroadcastReceiver;importandroid.content.Context;importandroid.content.Intent;importandroid.util.Log;publicclassShareBroadcastReceiverextendsBroadcastReceiver{@OverridepublicvoidonReceive(Contextcontext,

android - 我应该在 AsyncTask 中使用 Wea​​kReference<Context> 还是 Application Context?

我有点进退两难,希望大家能帮帮我。如你所见,我有一个AsyncTask我在其中保存了一些代码Bitmap将对象作为.jpg文件添加到图库中。在AsyncTask我也在使用Context,但据我所知,使用Activity的上下文在这个内部类中可能会导致内存泄漏,所以我将其更改为WeakReferenceweakContext;所以垃圾收集器可以收集它。但是通过使用Application我从传递的View中获得的上下文从构造函数我应该归档与弱上下文引用相同的效果那么在这种情况下使用哪个更好呢?publicclassViewToBitmap{privateViewview;privateWe

android - 使用 Context 获取 LayoutInflater

这两者有什么区别吗?inflater=(LayoutInflater)LayoutInflater.from(context);inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 最佳答案 目前还没有,正如您通过检查theLayoutInflatersourcecode可以看到的那样.from()将抛出一个Exception而不是返回null,但除此之外它们是相同的。就个人而言,我大部分时间都使用getLayoutIn

android - 构造函数 SimpleCursorAdapter(Context, int, Cursor, String[], int[]) 已弃用

如何解决这个问题?TheconstructorSimpleCursorAdapter(Context,int,Cursor,String[],int[])isdeprecated和ThemethodmanagedQuery(Uri,String[],String,String[],String)fromthetypeActivityisdeprecated代码如下:packagecom.example.kamusdigital;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.View;impor

android - 使用 Context.getText 和 Context.getResources.getText 有什么区别吗?

所以我注意到似乎有两种方法可以获取相同的数据,我不确定是否有关于何时应该使用其中任何一种的指南(除了绕过getResources可以节省内存,如果你实际上不想多次使用该对象)。但除此之外,我想知道是否有使用指南或理由Context.getText(id)与Context.getResources.getText(id)有人能帮忙吗? 最佳答案 没有区别。getText(id)的来源是:/***Returnalocalized,styledCharSequencefromtheapplication'spackage's*defaul

android - 什么是 Context.getExternalMediaDir()?

JavadocforEnvironment.getExternalStoragePublicDirectory()中的示例提到Context.getExternalMediaDir()但此方法在我的AndroidAPI版本中不可用,而且我无法在任何版本的任何地方找到它的记录。这是打字错误还是从未发布的内容?voidcreateExternalStoragePublicPicture(){//Createapathwherewewillplaceourpictureintheuser's//publicpicturesdirectory.Notethatyoushouldbecarefu

android - 如何避免 context.getSystemService(Context.CAMERA_SERVICE) 中的内存泄漏?

我在Android5.xCamera2API中发现了内存泄漏,我也是reported.问题是当您使用在LEGACY模式下实现Camera2API的AndroidLollipop设备时。在此类设备上,调用context.getSystemService(Context.CAMERA_SERVICE)会导致context被保留,这样它就不会被垃圾回收。如果此context是您多次启动的Activity,您最终可能会挂起对数十个从未被垃圾回收的Activity实例的引用。该问题似乎只发生在以LEGACY模式实现Camera2API的Lollipop设备上(例如HTCOneM8、Samsung

android - adb 无法识别 Samsung Note II 和 Note 10.1

要让adb识别我的手机和平板电脑,我需要做些什么特别的事情吗?我打开了开发者模式,但是当我执行“adbdevices”时,如果没有运行模拟器,我仍然只能获得模拟器或什么都没有。谢谢! 最佳答案 如果您在Windows下工作,请尝试安装SamsungUSBDriverforWindows..应该足够了;-) 关于android-adb无法识别SamsungNoteII和Note10.1,我们在StackOverflow上找到一个类似的问题: https://st

android - Galaxy Note II - values-xhdpi 还是 values-large?

如果我同时拥有values-xhdpi和values-large资源,galaxynoteII将使用哪一个?我没有用于测试的设备,模拟器只能带我到此为止。有什么想法吗? 最佳答案 根据precedencetable,large出现在xhdpi之前,因此来自values-large的值将在实际设备上使用。这里有一个重要的注意事项,如果设备实际声明自己具有大屏幕,就会发生这种情况。但是,设备对此不是很一致,所以我会考虑将资源添加到像sw600dp这样的文件夹中,因为它更可靠。有关更多详细信息,请阅读上面的链接并查看如何在bestprac