Tag: 安卓

为什么unregisterReceiver()永远不会调用onServiceDisconnected?

我绑定到我的活动中的服务: override fun onStart() { Timber.d("onStart") super.onStart() val intent = Intent(this, MyService::class.java) bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE) } 迄今为止工作。 然后bindService()调用onServiceConnected() : /** Defines callbacks for service binding, passed to bindService() */ private val serviceConnection = object : ServiceConnection { override fun onServiceConnected(className: ComponentName, service: IBinder) { // We've bound to MyService, cast the IBinder and get MyService […]

HttpException未被onError()捕获

我正在使用Retrofit2和RxJava2向后端服务器发送请求。 当答案是200或201时,一切正常。 当服务器的响应是409或503并引发HttpException ,它不会被Observable的onError()捕获,并且应用程序崩溃。 我正在做的请求是这样的: @POST("users/sign-up") fun register(@Body register: RegisterBody): Observable<User> 我做请求的代码片段是这样的( applySchedulers()只适用于subscribeOn()和observeOn() ): api.register(body) .compose(applySchedulers()) .subscribe( { user -> onNextRegister(user.id, email.toString(), password.toString()) }, { error -> handleRegistrationError(error) }) 引发的异常如下所示: io.reactivex.exceptions.CompositeException: 2 exceptions occurred. ComposedException 1 : retrofit2.adapter.rxjava2.HttpException: HTTP 503 Unavailable ComposedException 2 : kotlin.NotImplementedError: An operation is not implemented: not implemented 即使我为Observable实现onError() ,如何防止应用程序崩溃? 请注意, […]

SimpleXML在Thread.getContextClassLoader()返回的类加载器可能失败之后抛出ClassNotFoundException

在一些设备上,我有这个错误: W/ActivityThread: ClassLoader.loadClass: The class loader returned by Thread.getContextClassLoader() may fail for processes that host multiple applications. You should explicitly specify a context class loader. For example: Thread.setContextClassLoader(getClass().getClassLoader()); D/dalvikvm: GC_CONCURRENT freed 1499K, 11% free 14469K/16119K, paused 2ms+3ms, total 41ms D/dalvikvm: WAIT_FOR_CONCURRENT_GC blocked 25ms I/SurfaceTextureClient: [0x517af630] frames:42, duration:1.290000, fps:32.550117 E/rkqpKRQuestApplicationListener: RxJavaHooks onError: java.lang.ClassNotFoundException: red.kometa.quest.common.entities.Paragraph$Part$Action$Way$NormalBehaviour at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61) […]

Android Espresso IntentsMatcher适用于新设备,但不算旧

我有一个Espresso单元测试,似乎在较新的设备上工作,但在API 17设备上失败。 这是测试: Intents.init() [… more setup] onView(withId(R.id.username)) .perform(typeText("username")) .perform(closeSoftKeyboard()) onView(withId(android.R.id.button1)).perform((click())) // This part fails intended(hasComponent(AcceptedActivity::class.java.name)) 错误是: android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: Wanted to match 1 intents. Actually matched 0 intents. 我已经试过在intended被调用之前睡了1000毫秒的线程,但这似乎没有帮助。 任何想法,为什么它成功的一些设备,但不是旧的?

在蓝牙扫描期间找不到设备

我试图实现一个蓝牙扫描仪和记录有关设备的信息。 我遇到了两个问题,第一个问题handler.postDelayed似乎无法正常工作,因为它立即执行stopBleScan()方法。 第二个问题map bleScanResults总是长度为0,这意味着扫描器没有发现任何设备。 PS。 我检查所有必要的权限(位置也)。 码: class MainActivity : AppCompatActivity(), AnkoLogger { lateinit var deviceBluetoothAdapter: BluetoothAdapter val REQUEST_ENABLE_BT = 1 val REQUEST_FINE_LOCATION = 2 val SCAN_PERIOD: Long = 6000 lateinit var bleScanner : BluetoothLeScanner lateinit var bleScanResults: Map<String, BluetoothDevice> lateinit var bleScanCallback: ScanCallback override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val bluetoothManager: BluetoothManager = […]

如何使用Anko DSL制作通用AppBar?

我正在尝试制作一个可以插入其他Anko组件的工具栏。 这是我要做的一个例子: class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) MainUI().setContentView(this) val toolbar: Toolbar = find(R.id.toolbar) setSupportActionBar(toolbar) } } class MainUI : AnkoComponent<MainActivity> { override fun createView(ui: AnkoContext<MainActivity>) = with(ui) { coordinatorLayout { fitsSystemWindows = true lparams { width = matchParent height = matchParent } ToolbarUI().createView(ui).lparams { width = matchParent } recyclerView […]

输入自己的值来组合最新

我有这个最好的流动性: private val subject: BehaviorSubject<Int> = BehaviorSubject.create() Flowable.combineLatest( materialA, materialB, subject.toFlowable(LATEST), Function3 { ma, mb, index -> if(index == 0) … else if(index ==1) … else … } subject.onNext(99) 基本上,我想观察这两个材料的数据库变化,并结合他们向用户显示一些数据。 有时,我需要使用最新的输出,并做一个不同的组合(计算量大)。 这就是为什么我把这个index作为一个来源。 这是一个有效的方法,还是有更好的选择? PS。 我需要能够随时要求一个不同的组合(这是我没有使用Flowable.just()),我想避免保存在obs链之外的状态。

从listView自动增量到Firestore文档

所以我有一个列表,可以填充我有一个微调项目。 然后我有一个文本框键入文档名称。 这两个都在工作 我需要的是我的代码自动检测我添加到列表中的项目数。 我不想手动添加它们。 我试过,但没有奏效 createListBtn.setOnClickListener { var item: String = "item" var i:Int = 1 var newItem: String = "item" + (Integer.parseInt(item.substring(1,item.length))+1) val list = HashMap<String, String>() list.put(newItem, kitList.toString()) db.collection("TestList").document(listNameTxt.text.toString()) .set(list as Map<String, Any>) .addOnSuccessListener { Log.d("TAG", "DocumentSnapshot successfully written!") } .addOnFailureListener { e -> Log.w("TAG1", "Error writing document") }

从Activity 中调用Fragments演示者的方法

我有2个不同的片段,他们都将通过2个不同的活动使用。 在两个活动的布局中,都有一个框架布局用作碎片容器。 哪个是; 碎片:MapFragment,ListFragment 活动:HomeActivity,SearchActivity。 让我们谈谈HomeActivity; HomeActivity会将ListFragment和MapFragment注入到onCreate活动中,并将注入的片段推送到它的布局(首先是列表片段),之后活动将调用注入片段的呈现器方法在列表或地图上显示服务结果。 代码; 片段一面; @CustomScope @Component(dependencies = NetComponent.class, modules = {ChallengeListFrgModule.class, ChallengeRepositoryModule.class}) public interface ChallengeListFrgComponent{ void inject(ChallengeListFragment fragment); } _ @Module class ChallengeListFrgModule(private val mView: ChallengeListFrgContract.View) { @Provides internal fun providesChallengeListFrgContractView(): ChallengeListFrgContract.View { return mView } } ListFrgPresenter: public class ChallengeListFrgPresenter implements ChallengeListFrgContract.Presenter { //region Variables ChallengeListFrgContract.View mView; ChallengeRepository challengeRepository; […]

NoClassDefFoundError okhttp3.internal.io.FileSystem

我使用okhttp 3.6.0 , RxJava 2.01 。 android studio canery 6 。 我正在缓存中遇到一些问题。 fun cache(context: Context): Cache { return Cache(context.cacheDir,30 * 1000 * 1000) } 上面的方法在Android版本6.0中运行良好,但是当我在android 4.4(kitkat)中运行这个应用程序崩溃与ClassDefNotFoundError 。 java.lang.NoClassDefFoundError:okhttp3.internal.io.FileSystem 在okhttp3.Cache。(Cache.java:178) 任何人都可以提出可能是什么问题?