小编Vil*_*lla的帖子

是否保证调用Activity.onStop()(API 11 +)

从文档中(至少对我来说)不清楚是否保证调用Activity.onStop.有两个地方看似矛盾的信息.

  1. Activity.onStop的Javadoc:

请注意,在内存不足的情况下,可能永远不会调用此方法,在这种情况下,系统没有足够的内存来保持活动进程在调用onPause()方法后运行.

  1. 活动类http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle的文档(特别是"Killable"列):

从Honeycomb开始,应用程序在其onStop()返回之前不处于killable状态.这可能会在调用onSaveInstanceState(Bundle)时产生影响(可以在onPause()之后安全地调用它,并允许和应用程序安全地等到onStop()以保存持久状态.

找到两种文件都说实话的方式有点困难.我能想到的唯一场景是:假设您正在使用目标API 21(使用min sdk 10)进行开发,并使用onStop()方法编写Activity.如果您随后在API 10手机上运行此应用程序,则无法保证调用onStop().这种情况意味着上述第1点和第2点的文档都是正确的.否则,其中一个必须是假的.

activity-lifecycle android-activity

14
推荐指数
2
解决办法
2023
查看次数

错误:找不到符号@dagger.Module(包括= {InflationInject_ViewModule.class})

我尝试在我的项目中AssistedInject使用 Dagger 2 ( https://github.com/square/AssistedInject ) 实现 Jake Wharton 的。

我的代码与https://github.com/square/AssistedInject/tree/master/inflation-inject-sample/src/main/java/com/example几乎相同,但出现错误:

错误:找不到符号@dagger.Module(包括= {InflationInject_ViewModule.class})

生成的代码似乎ViewModule不知道在哪里可以找到InflationInject_ViewModule

@InflationModule
@Module(includes = [InflationInject_ViewModule::class])
abstract class ViewModule
Run Code Online (Sandbox Code Playgroud)

我的 build.gradle 的相关部分是

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {...}

dependencies {
  implementation "com.google.dagger:dagger-android:2.16"
  implementation "com.google.dagger:dagger-android-support:2.16"
  kapt "com.google.dagger:dagger-compiler:2.16"
  kapt "com.google.dagger:dagger-android-processor:2.16"
  implementation 'com.squareup.inject:inflation-inject:0.3.0'
  kapt 'com.squareup.inject:inflation-inject-processor:0.3.0'
}
Run Code Online (Sandbox Code Playgroud)

我已经检查过它InflationInject_ViewModule确实存在于生成的代码中(at build/generated/source/kapt/devDebug/com/project/di/,所以可能与编译器查找源集/生成的代码的位置有关。

有什么建议么?

generated-code assisted-inject dagger-2

4
推荐指数
1
解决办法
3071
查看次数

PowerMock:如何在Spy上抑制父方法?

如何在Spy上正确抑制父类方法?

如果我有一个班级家长:

public class Parent {
    public void method() {
    System.out.println("Parent.method");
    }
}

class Child extends Parent {
@Override
    public void method() {
        super.method();
        System.out.println("Child.method");
    }
}
Run Code Online (Sandbox Code Playgroud)

我用以下代码测试:

@RunWith(PowerMockRunner.class)
@PrepareForTest(Parent.class)
public class SuppressParentTest {
   @Spy Child child = new Child();

   @Test
   public void testSuppressSuperclassMethods() {
       PowerMockito.suppress(methodsDeclaredIn(Parent.class));
       child.method();
   }
Run Code Online (Sandbox Code Playgroud)

我从System.out获得以下打印输出:

Parent.method
Child.method
Run Code Online (Sandbox Code Playgroud)

而我应该只打印一份Child.method.

有趣的是,如果我@Spy从Child对象的声明中删除注释,则会Parent.method()被正确抑制.

难道我做错了什么?我是否误解了如何使用PowerMock?

java mockito powermock powermockito

3
推荐指数
1
解决办法
3759
查看次数