草庐IT

android - activity.isFinishing 语句中的 BadTokenException : Unable to add window -- token null is not valid; is your activity running?

如果用户仍在当前Activity中,我有一个需要显示的弹出窗口,几秒钟后。我实现了stament检查Activity是否未完成/销毁然后显示弹出窗口,它工作正常,周末用户:)(从一个Activity慢慢点击到另一个Activity)但在高压测试中(Activity正在重新创建,完成,快速移动形式Activity到Activity)给我那个错误:E/UncaughtException:android.view.WindowManager$BadTokenException:Unabletoaddwindow--tokennullisnotvalid;isyouractivityrunni

android - 使用 Locale.getDefault() 和 context.getResources().getConfiguration().locale 的语言环境有什么区别?

返回的字符串有什么区别吗:Locale.getDefault().toString()和context.getResources().getConfiguration().locale.toString()询问是因为我怀疑这会导致应用程序中出现错误,在使用Locale.getDefault().toString()之前有效的功能不再适用于context.getResources()。getConfiguration().locale.toString(),在某些美国设备上。但不确定是否是这个原因。谢谢! 最佳答案 Locale.ge

android - 以编程方式在所有 API 级别上启用飞行模式 Android

如何在单击按钮时以编程方式启用/禁用飞行模式?这个我试过了//readtheairplanemodesettingbooleanisEnabled=Settings.System.getInt(getContentResolver(),Settings.System.AIRPLANE_MODE_ON,0)==1;//toggleairplanemodeSettings.System.putInt(getContentResolver(),Settings.System.AIRPLANE_MODE_ON,isEnabled?0:1);//PostanintenttoreloadInten

java - 尝试在空对象引用上调用虚拟方法 'android.os.Looper android.content.Context.getMainLooper()'

这个问题在这里已经有了答案:WhatisaNullPointerException,andhowdoIfixit?(12个答案)关闭5年前。每当我尝试在我的手机或模拟器上打开该应用程序时,我的Logcat中都会出现此错误。为了让您大致了解我目前正在做的项目,它是一个记录连接到手机接入点的设备数据的系统,可以通过屏幕上的按钮打开和关闭。我想归功于:Android2.3wifihotspotAPI和https://www.whitebyte.info/android/android-wifi-hotspot-manager-classLogcat文件的图像是:https://i.gyazo

android - 如何在另一个自定义 View 中添加自定义 View ?

我正在尝试将CustomViewBeta(一个扩展的RelativeLayout)添加到CustomViewAlpha(一个扩展的LinearLayout)——想法是CustomViewAlpha将包含一堆CustomViewBetas和ListView。无论我尝试什么,它都不起作用。我要么什么都看不到——没有CustomViewBetas,要么当我在CustomViewBeta中的一个TextView上尝试setText时它给了我一个NPECustomViewAlpha工作正常,因为它是硬编码在fragment的XML中的:代码为:publicclassCustomViewAlpha

android - 无法关闭/隐藏 Android 5.0 Lollipop 上的警报图标

自AndroidLollipop5.0(API21)发布以来,现在有一个API可以正式显示/隐藏闹钟图标。关于此here有更多信息在stackoverflow上。多亏了它,我现在才能够在5.0+Android设备上显示闹钟图标。不幸的是,如果警报被禁用,我无法关闭/隐藏/取消图标。这是我正在做的事情(结合了Stackoverflow和Android股票警报的多次尝试):publicstaticvoidsetNextAlert(finalContextcontext){finalAlarmalarm=calculateNextAlert(context);AlarmManageram=(

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

java - java.lang.Throwable : setStateLocked?之类的错误如何解决

我正在开发一个应用程序。在其中我使用的是ListView。当我单击列表项时,它应该转到下一个Activity,即ProfileActivity2.java。它工作正常,但在此ProfileActivty2底部有一个按钮,当我单击此按钮时,我的应用程序崩溃并停止在ListView页面中。并在listview布局文件中显示错误java.lang.Throwable:setStateLocked即AtsetContentView。我该如何解决这个错误?//ProfileActivity2.javapublicclassProfileActivity2extendsAppCompatActiv

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