小编j2e*_*nue的帖子

RxJava - Just vs From

在以下情况下使用Observable.justvs 时我得到相同的输出Observable.from:

 public void myfunc() {
 //swap out just for from here and i get the same results,why ?
        Observable.just(1,2,3).subscribe(new Subscriber<Integer>() {
            @Override
            public void onCompleted() {
                Log.d("","all done. oncompleted called");
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(Integer integer) {
                Log.d("","here is my integer:"+integer.intValue());
            }
        });

    }
Run Code Online (Sandbox Code Playgroud)

我想只是just假设发出一个项目,from并在某种列表中发出项目.有什么不同 ?我也注意到这一点just并且from仅涉及有限数量的论点.所以Observable.just(1,2,3,4,5,6,7,8,-1,-2)没关系,但Observable.just(1,2,3,4,5,6,7,8,-1,-2,-3)失败了.同样,我必须将它包装在一个列表或数组中.我只是好奇他们为什么不能定义无限的论点.

更新:我试验过,看到它just不采用数组结构,它just需要参数.from收集一个集合.以下是适用于from但不适用于just …

java rx-java

32
推荐指数
2
解决办法
1万
查看次数

Android room persistent library - TypeConverter错误错误:无法弄清楚如何将字段保存到数据库"

由于错误,我无法在房间内创建typeConverter.我似乎每个文档都遵循一切.我想将列表转换为json字符串.让我们来看看我的实体:

      @Entity(tableName = TABLE_NAME)
public class CountryModel {

    public static final String TABLE_NAME = "Countries";

    @PrimaryKey
    private int idCountry;
/* I WANT TO CONVERT THIS LIST TO A JSON STRING */
    private List<CountryLang> countryLang = null;

    public int getIdCountry() {
        return idCountry;
    }

    public void setIdCountry(int idCountry) {
        this.idCountry = idCountry;
    }

    public String getIsoCode() {
        return isoCode;
    }

    public void setIsoCode(String isoCode) {
        this.isoCode = isoCode;
    }

    public List<CountryLang> getCountryLang() {
        return countryLang;
    }

    public void setCountryLang(List<CountryLang> countryLang) { …
Run Code Online (Sandbox Code Playgroud)

android android-room

30
推荐指数
7
解决办法
4万
查看次数

iOS - 在故事板中管理代码合并的最佳实践

在xcode故事板中与许多团队成员合并会产生许多冲突等.我需要一个策略来与20个团队成员共享故事板,但要避免与在故事板中合并代码相关联的噩梦.

我想在xcode中为每个团队设置一个单独的目标,但这并不好,因为我们都需要更新所以有两个故事板并不是一个好习惯.

我的代码库是继承的.它是一个分叉的项目,故事板很重.我认为改用xib可能很难(??)

xcode storyboard git-merge ios uistoryboard

29
推荐指数
2
解决办法
2万
查看次数

Android room persistent library - 如何插入具有List对象字段的类

Android房间持久化库中如何将整个Model对象插入到本身具有另一个列表的表中.

让我告诉你我的意思:

@Entity(tableName = TABLE_NAME)
public class CountryModel {

    public static final String TABLE_NAME = "Countries";

    @PrimaryKey
    private int idCountry;

    private List<CountryLang> countryLang = null;

    public int getIdCountry() {
        return idCountry;
    }

    public void setIdCountry(int idCountry) {
        this.idCountry = idCountry;
    }

    public String getIsoCode() {
        return isoCode;
    }

    public void setIsoCode(String isoCode) {
        this.isoCode = isoCode;
    }

    /** 
        here i am providing a list of coutry information how to insert 
        this into db along with CountryModel at same …
Run Code Online (Sandbox Code Playgroud)

android android-room

28
推荐指数
5
解决办法
4万
查看次数

Android studio警告 - InnerClass注释缺少相应的EnclosingMember注释

我最近升级到Android Studio 3.1,在使用Java项目构建我的Kotlin时,我收到了以下警告.

InnerClass注释缺少相应的EnclosingMember注释.这样的InnerClass注释被忽略.

消息{kind = WARNING,text = InnerClass注释缺少相应的EnclosingMember注释.这样的InnerClass注释被忽略.,sources = [Unknown source file]}

这是我的Gradle详细信息.

android {
compileSdkVersion 27
//buildToolsVersion '27.0.3'
defaultConfig {
    minSdkVersion 16
    targetSdkVersion 27
    applicationId "org.myapp"
    versionCode generateVersionCode()
  //...
    multiDexEnabled true
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
Run Code Online (Sandbox Code Playgroud)

它并没有指出我的问题所在.如何找到有问题的代码?

在此输入图像描述

android java-annotations

26
推荐指数
1
解决办法
1万
查看次数

Mockito - 验证方法有什么作用?

假设我有以下psuedo测试代码:

 //Let's import Mockito statically so that the code looks clearer
 import static org.mockito.Mockito.*;

 //mock creation
 List mockedList = mock(List.class);

 //using mock object
 mockedList.add("one");
 mockedList.clear();

 //what do these two verify methods do ?
 verify(mockedList).add("one");
 verify(mockedList).clear();
Run Code Online (Sandbox Code Playgroud)

我一直在显示测试通过,但我不知道验证意味着什么?什么是确切的验证?我知道我嘲笑了一个添加和清除的调用,但这两个验证调用有什么作用?

android unit-testing mocking mockito

24
推荐指数
2
解决办法
9301
查看次数

找不到android ContextCompat.checkSelfPermission()

我试图使运行时权限向后兼容旧设备,但使用支持库我无法checkSelfPermission()ContextCompat课堂上找到静态调用,但它在此处记录

这是我的项目gradle设置:

defaultConfig {
    applicationId "org.myprogram.cool"
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 39
    versionName "3.0"
}
Run Code Online (Sandbox Code Playgroud)

这是依赖项:

compile 'com.google.android.gms:play-services:+'
compile 'com.squareup:otto:1.3.5'
compile 'com.android.support:appcompat-v7:22.1.1'
Run Code Online (Sandbox Code Playgroud)

知道我错过了什么吗?

android android-support-library

24
推荐指数
2
解决办法
4万
查看次数

Android-在shape标签中使用useLevel

android shape xml标签useLevel属性的目的是什么?这与图层列表有关,但无关紧要.从文档我发现useLevel标记的meanging:

指示drawable的级别是否影响绘制渐变的方式.

所以如果我有以下xml片段:

    <?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="ring"
    android:innerRadius="15dp"
    android:thickness="10dp"
    android:useLevel="false">

    <solid android:color="#ababf2" />

    <size
        android:height="50dp"
        android:width="50dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)

然后使用useLevel = true,禁用戒指.戒指出现必定为假.但是这个属性的目的是什么?文档不清楚.

xml android layer-list android-drawable

20
推荐指数
1
解决办法
6711
查看次数

Rxjava2只是方法 - 如何在另一个线程上运行房间插入?

我有一个房间持久数据库插入方法,如下所示:

@Dao
public interface CountriesDao{

    @Insert(onConflict = REPLACE)
    List<Long> addCountries(List<CountryModel> countryModel);
}
Run Code Online (Sandbox Code Playgroud)

我意识到这不能在主线程上运行.以下是我定义数据库的方法:

Room.inMemoryDatabaseBuilder(context.getApplicationContext(), MyDatabase.class).build();
Run Code Online (Sandbox Code Playgroud)

我试图使用rxjava2,以便我不在主线程上运行.我创建了以下方法:

public void storeCountries(List<CountryModel> countriesList) {
        Observable.just(db.countriesDao().addCountries(countriesList))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new DefaultSubscriber<List<Long>>(){
            @Override
            public void onSubscribe(@NonNull Disposable d) {
                super.onSubscribe(d);
            }

            @Override
            public void onNext(@NonNull List<Long> longs) {
                super.onNext(longs);
                Timber.d("insert countries transaction complete");
            }

            @Override
            public void onError(@NonNull Throwable e) {
                super.onError(e);
                Timber.d("error storing countries in db"+e);
            }

            @Override
            public void onComplete() {
                Timber.d("insert countries transaction complete");
            }
        });
    }
Run Code Online (Sandbox Code Playgroud)

对我来说,这显然是在另一个线程上运行.不是主线程,但是当我运行此代码时,我收到以下错误:

完整的堆栈跟踪如下.为什么会这样?

进程:com.mobile.myapp.staging,PID:12990
java.lang.IllegalStateException:调度程序抛出致命异常.引起:java.lang.IllegalStateException:无法访问主线程上的数据库,因为它可能会长时间锁定UI.at io.reactivex.android.schedulers.HandlerScheduler $ …

android rx-java android-room

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

Android -room持久库 - DAO调用是异步的,因此如何获得回调?

从我所读的内容Room不允许您在主线程上发出数据库查询(因为可能导致主线程的延迟)). 所以想象一下,我正在尝试更新UI主线程上的textview哪些数据如何才能收到回调.让我举个例子.想象一下,我想将我的业务模型数据存储到一个名为Events的对象中.因此我们有一个EventDao对象:

想象我们在下面有这个DAO对象:

@Dao
public interface EventDao {

   @Query("SELECT * FROM " + Event.TABLE_NAME + " WHERE " + Event.DATE_FIELD + " > :minDate" limit 1)
   LiveData<List<Event>> getEvent(LocalDateTime minDate);

   @Insert(onConflict = REPLACE)
   void addEvent(Event event);

   @Delete
   void deleteEvent(Event event);

   @Update(onConflict = REPLACE)
   void updateEvent(Event event);

}
Run Code Online (Sandbox Code Playgroud)

现在在一些活动中,我有一个textview,我想更新它的值,所以我这样做:

 myTextView.setText(EventDao.getEvent(someDate));/*i think this is illegal as im trying to call room dao on mainthread, therefore how is this done correctly ? would i need to show a spinner while it updates ?*/ …
Run Code Online (Sandbox Code Playgroud)

android android-room

17
推荐指数
2
解决办法
2万
查看次数