我有一个活动,向用户显示项目列表,并使用分页库.我的问题是,当用户向下滑动屏幕时,我无法重新加载列表,以便它再次从服务器获取数据.
这是我的DataSource Factory:
public class CouponListDataSourceFactory extends DataSource.Factory {
private CouponListDataSource dataSource;
public CouponListDataSourceFactory(CouponRepository repository, String token, String vendorId) {
dataSource = new CouponListDataSource(repository, token, vendorId);
}
@Override
public DataSource create() {
return dataSource;
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我创建PagedList的方法
PagedList.Config config = new PagedList.Config.Builder()
.setInitialLoadSizeHint(15)
.setPageSize(10)
.build();
LiveData<PagedList<Coupon>> couponsLiveData = new LivePagedListBuilder<>(dataSourceFactory, config).build();
Run Code Online (Sandbox Code Playgroud) 我正在使用导航体系结构组件库,我的应用程序的起点是以下片段:
class MainFragment : BaseFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_main, container, false)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
}
Run Code Online (Sandbox Code Playgroud)
继承于抽象类BaseFragment:
abstract class BaseFragment : Fragment() {
}
Run Code Online (Sandbox Code Playgroud)
当我运行我的应用程序时,我得到:
Unable to instantiate fragment io.example.MainFragment: calling Fragment constructor caused an exception
Run Code Online (Sandbox Code Playgroud)
但是,如果使用MainFragmentExtended Fragment而不是则不会发生这种情况BaseFragment。是什么原因?这与导航体系结构组件的工作方式有关吗?
在我的应用程序中,我让用户从他们的图库中选择一张照片 我使用这样的意图:
Intent pickPictureIntent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
Run Code Online (Sandbox Code Playgroud)
在我开始这个意图之前,我检查是否有任何应用程序可以处理它:
if (pickPictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivityForResult(pickPictureIntent, SELECT_PICTURE_FROM_GALLERY_REQUEST_CODE);
}
Run Code Online (Sandbox Code Playgroud)
但是当我的两个用户尝试从他们的图库中选择一张照片时会遇到此异常:
Exception android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.PICK dat=content://media/external/images/media }
Run Code Online (Sandbox Code Playgroud)
到目前为止,我知道当没有活动来处理意图时会发生这种情况,但正如你所看到的,我检查了没有活动来处理我的代码中的意图的可能性.
我无法使用Android 27作为目标SDK和27.0.3作为buildToolsVersion构建项目.
我的Android工作室版本是3.0.1,我在项目的buid.gradle中的存储库中也有google().
我收到此错误:
> Could not resolve com.android.support:design:27.0.3.
> Failed to download SHA1 for resource 'https://maven.google.com/com/android/support/design/27.0.3/design-27.0.3.pom'.
> For input string: "<!"
Run Code Online (Sandbox Code Playgroud) 当我尝试通过在每次离开活动并返回时在开发人员选项中启用“不要保留活动”来模拟应用程序中的配置更改时,将ViewModel重新创建该活动!不ViewModels应该处理这些情况吗?
我可以通过保存活动状态来解决此问题,onSaveInstanceState但是使用a的意义ViewModel何在?