gpt4 book ai didi

java - Android:无法调用 finish()

转载 作者:行者123 更新时间:2023-12-02 01:23:03 24 4
gpt4 key购买 nike

为什么我无法在下面的代码中调用finish()?我也无法启动任何 Intent。

这是我的代码:

public class EditProfilePresenter<V extends EditProfileView> extends PickImagePresenter<V> {
protected Profile profile;
protected ProfileManager profileManager;

protected EditProfilePresenter(Context context) {
super(context);
profileManager = ProfileManager.getInstance(context.getApplicationContext());
}

public void loadProfile() {
ifViewAttached(BaseView::showProgress);
profileManager.getProfileSingleValue(getCurrentUserId(), new OnObjectChangedListenerSimple<Profile>() {
@Override
public void onObjectChanged(Profile obj) {
profile = obj;
ifViewAttached(view -> {
if (profile != null) {
view.setName(profile.getUsername());
if (profile.getPhotoUrl() != null) {
view.setProfilePhoto(profile.getPhotoUrl());
}
}
view.hideProgress();
view.setNameError(null);
});
}
});
}

public void attemptCreateProfile(Uri imageUri) {
if (checkInternetConnection()) {
ifViewAttached(view -> {
view.setNameError(null);
String name = view.getNameText().trim();
boolean cancel = false;
if (TextUtils.isEmpty(name)) {
view.setNameError(context.getString(R.string.error_field_required));
cancel = true;
} else if (!ValidationUtil.isNameValid(name)) {
view.setNameError(context.getString(R.string.error_profile_name_length));
cancel = true;
}
if (!cancel) {
view.showProgress();
profile.setUsername(name);
createOrUpdateProfile(imageUri);
}
});
}
}

private void createOrUpdateProfile(Uri imageUri) {
profileManager.createOrUpdateProfile(profile, imageUri, (boolean success) -> {
ifViewAttached(view -> {
view.hideProgress();
if (success) {
onProfileUpdatedSuccessfully();
// ----- HERE -----
System.exit(0);
// I can't call finish(), but can call System.exit().
} else {
view.showSnackBar(R.string.error_fail_create_profile);
}
});
});
}

protected void onProfileUpdatedSuccessfully() {
ifViewAttached(BaseView::finish);
}
}

启动一个 Intent 将用户发送回 LoginActivity (这将检查是否有用户)将是最好的解决方案,但问题是我无法启动 Intent (它说:“无法解析构造函数”)。

最佳答案

您只能对 Activity 调用 finish()。您发布的代码不是Activity

关于java - Android:无法调用 finish(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57350655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com