我尝试在Android Studio中启用Java 8功能,如https://android.com中所示:
defaultConfig {
...
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Run Code Online (Sandbox Code Playgroud)
之后我添加了compile 'net.sourceforge.streamsupport:streamsupport:1.5.1'并且能够使用lambdas.自从我完成了这项工作以来,Gradle构建需要永远(我在20分钟后尝试其他解决方案就杀了这个过程).我的硬件不是很好,但仍然不是一个可接受的构建时间(它从未完成).我也试图删除这些更改,但我面临相关的编译错误.
我可以从git中提取以前的应用程序版本,但我宁愿解决这些问题以便能够使用Java 8的功能.有没有人面对这个问题并设法解决它?谢谢.
我正在尝试从其Google Plus帐户中获取用户的信息,包括性别和年龄.由于这些字段可能是私有的,我认为明确请求它们可以解决问题.但是,尽管登录对话框明确指出应用程序请求View your complete date of birth,但我未能获得生日.
这些是我的范围(尝试了很多变化):
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
//.requestScopes(new Scope(Scopes.PROFILE))
//.requestScopes(new Scope(Scopes.PLUS_LOGIN))
.requestScopes(new Scope("https://www.googleapis.com/auth/user.birthday.read"),
new Scope("https://www.googleapis.com/auth/userinfo.profile"))
//.requestProfile()
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addApi(Plus.API)
.addScope(new Scope(Scopes.PROFILE))
.build();
Run Code Online (Sandbox Code Playgroud)
使用不推荐使用的getCurrentPerson时onActivityResult,我得到null值:
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (mGoogleApiClient.hasConnectedApi(Plus.API)) {
Person person = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
if (person != null) {
Log.i(TAG, person.getDisplayName()); //returns full name successfully
Log.i(TAG, person.getGender()); //0
Log.i(TAG, person.getBirthday()); //null
}
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试从帐户( …
android google-plus google-play-services google-plus-signin google-signin
我实现了MVP模式的应用程序Loader,以保持对视娱乐演示对象(有关于这个的文章在这里).我是Dagger 2的新手,试图与当前代码一起实现它.
我已经设法使它工作,但现在我的演示者创建了两次.起初它是使用初始化的工厂类创建的onCreateLoader,但是当添加Dagger 2实现时,我创建了两个对象(在工厂类和注入时).
现在我避免创建一个新的演示者onCreateLoader并改为传递注入的演示者.问题在于视图重新创建:每次销毁和重新创建视图时,都会在OnCreate/中注入一个新的演示者OnCreateView.这是场景:
注入一个新的演示者:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
...
getControllerComponent().inject(this);
...
}
Run Code Online (Sandbox Code Playgroud)初始化Loader,onCreateLoader被称为如果Loader不存在.请注意,我们通过了注入的演示者:
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getLoaderManager().initLoader(PRESENTER_LOADER_ID, null, this);
}
@Override
public Loader<MyPresenter> onCreateLoader(int id, Bundle args) {
switch (id) {
case PRESENTER_LOADER_ID:
return new PresenterLoader<>(getContext(), presenter);
//return new PresenterLoader<>(getContext(), new MyPresenterFactory());
}
return null;
}
Run Code Online (Sandbox Code Playgroud)分配从中收到的演示者Loader.如果它刚刚创建,我们分配已经分配的相同对象,所以没有任何反应.但是,如果视图被重新创建,那么Dagger 2会注入一个新的演示者,在这里我们扔掉新的演示者并用旧的演示者替换它 …