编辑:似乎是谷歌方面的一个错误.错误报告:https://issuetracker.google.com/issues/79235243
自谷歌发布新的更改()后,我不得不更新谷歌服务.一旦我做了,我得到这个gradle错误:
More than one variant of project :myModule matches the consumer attributes:
- Configuration ':myModule:debugApiElements' variant android-aidl:
- Found artifactType 'android-aidl' but wasn't required.
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
- Configuration ':myModule:debugApiElements' variant android-classes:
- Found artifactType 'android-classes' but wasn't required.
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' and …Run Code Online (Sandbox Code Playgroud) 我想做这个:
Observable.just(bitmap)
.map(new Func1<Bitmap, File>() {
@Override
public File call(Bitmap photoBitmap) {
//File creation throws IOException,
//I just want it to hit the onError() inside subscribe()
File photoFile = new File(App.getAppContext().getCacheDir(), "userprofilepic_temp.jpg");
if(photoFile.isFile()) {//delete the file first if it exists otherwise the new file won't be created
photoFile.delete();
}
photoFile.createNewFile(); //saves the file in the cache dir
FileOutputStream fos = new FileOutputStream(photoFile);
photoBitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);//jpeg format
fos.close();
return photoFile;
}
})
.subscribe(//continue implementation...);
Run Code Online (Sandbox Code Playgroud)
基本上在call()方法中,它可以抛出异常.如何让Observer处理它onError().或者这不是思考这个问题的正确方法吗?
我刚刚开始使用RxJava/RxAndroid.我想避免上下文泄漏,所以我创建了一个像这样的BaseFragment:
public abstract class BaseFragment extends Fragment {
protected CompositeSubscription compositeSubscription = new CompositeSubscription();
@Override
public void onDestroy() {
super.onDestroy();
compositeSubscription.unsubscribe();
}
}
Run Code Online (Sandbox Code Playgroud)
在我的片段中扩展了BaseFragment,我这样做:
protected void fetchNewerObjects(){
if(!areNewerObjectsFetching()){ //if it is not already fetching newer objects
Runtime.getRuntime().gc();//clean out memory if possible
fetchNewObjectsSubscription = Observable
.just(new Object1())
.map(new Func1<Object1, Object2>() {
@Override
public Object2 call(Object1 obj1) {
//do bg stuff
return obj2;
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Object2>() {
@Override
public void onCompleted() {
compositeSubscription.remove(fetchNewObjectsSubscription);
fetchNewObjectsSubscription = null;
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 我实现了一个ReceylerView,我无法弄清楚如何获得触摸反馈(来自它的涟漪效应).
这是我为onClickListener所做的:
holder.itemView.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
//start Intent
}
});
Run Code Online (Sandbox Code Playgroud)
我将可点击和可聚焦添加到我的XML中.这是回收者视图膨胀的内容:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:padding="4dp" >
Run Code Online (Sandbox Code Playgroud) java android android-listview recycler-adapter android-recyclerview
让我们使用这个类作为例子:
public static class CurrentUser{
public static Observable<User> get(){
//code basically returns the currently logged in User object
//but sometimes there may not be a logged in user
}
public static Observable<PutResult> logOut(){
return get()
//I only want to execute the following if user != null
.flatMap(new Func1<User, Observable<PutResult>>() {
@Override
public Observable<PutResult> call(User user) {
//delete the session token and save
user.removeSessionToken();
return DatabaseModule.getStorIOSQLite()
.put()
.object(user)
.prepare()
.asRxObservable();
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
我应该在flatmap中返回null吗?这是否有任何影响,因为它期待一个Observable?
我正在使用Stheto在我的Android应用程序中检查数据库,但是当表中有很多对象时,我在所有列中看到"截断".我怎么能看到他们呢?
在DebugTree日志中,我看到了类名,但是当我创建自定义树时,标签就是null.这是我的自定义树的样子:
public class CrashlyticsTree extends Timber.Tree {
private static final String CRASHLYTICS_KEY_PRIORITY = "priority";
private static final String CRASHLYTICS_KEY_TAG = "tag";
private static final String CRASHLYTICS_KEY_MESSAGE = "message";
@Override
protected boolean isLoggable(int priority) {
if (priority == Log.VERBOSE || priority == Log.DEBUG || priority == Log.INFO) {
return false;
}
// only log WARN(Timber.w), ERROR(Timber.e), or WTF(Timber.wtf)
return true;
}
@Override
protected void log(int priority, @Nullable String tag, @Nullable String message, @Nullable Throwable t) {
if(User.CurrentUser.isLoggedIn()){ …Run Code Online (Sandbox Code Playgroud) 我想添加实例ID(最后一行)
dependencies {
//Basic Google libs
compile 'com.android.support:support-v4:+'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services-base:7.5.0'
compile 'com.google.android.gms:play-services-gcm:7.5.0'
compile 'com.google.android.gms:play-services-location:7.5.0'
compile 'com.google.android.gms:play-services-maps:7.5.0'
compile 'com.google.android.gms:play-services-wallet:7.5.0'
compile 'com.google.android.gms.iid:7.5.0'
}
Run Code Online (Sandbox Code Playgroud)
但我一直在:
错误:无法解决:com.google.android.gms.iid:7.5.0:
有什么线索的原因?
这是一个例子:
return ApiClient.getPhotos()
.subscribeOn(Schedulers.io())
.map(new Func1<APIResponse<PhotosResponse>, List<Photo>>() {
@Override
public List<Photo> call(CruiselineAPIResponse<PhotosResponse> response) {
//convert the photo entities into Photo objects
List<ApiPhoto> photoEntities = response.getPhotos();
return Photo.getPhotosList(photoEntities);
}
})
.subscribeOn(Schedulers.computation())
Run Code Online (Sandbox Code Playgroud)
我是否需要两者.subscribeOn(Schedulers.computation()),.subscribeOn(Schedulers.computation())因为它们适用于不同的Observable?
我有一个父视图,其根视图是CoordinatorLayout。父级布局包含TabLayout和ViewPager。在ViewPager包含两个子片段。子片段CoordinatorLayout的根视图也有一个,并包含一个RecyclerView。这是我的xml文件:
上级:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/explore_viewpager"
android:layout_width="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_height="match_parent"/>
<android.support.design.widget.AppBarLayout
android:id="@+id/main_activity_appbar"
android:layout_width="match_parent"
app:elevation="2dp"
android:layout_height="wrap_content">
<android.support.design.widget.TabLayout
android:id="@+id/explore_tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways|snap"
android:background="@color/tab_layout_bg"
app:tabIndicatorColor="@color/tab_indicator_color"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
儿童:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/basic_recycler_view_layout_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:scrollbars="vertical"
android:clipToPadding="false"
android:paddingTop="@dimen/single_margin"
android:paddingBottom="@dimen/single_margin"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试显示SnackBar子片段中的一个时,它不显示,并且隐藏在屏幕外。如果滚动子片段,则TabLayout父片段中的会折叠(按预期方式)并SnackBar出现。我四处搜索,它的行为与此类似:带有Coordinator布局的ViewPager片段中的Android设计支持库FAB,但SnackBar完全隐藏了。我认为这是因为TabLayout和SnackBar具有相同的高度。
如何设置布局以SnackBar显示?
解释起来有点复杂,所以请让我知道是否可以澄清任何部分。
android android-fragments android-viewpager android-snackbar android-coordinatorlayout