Java 安卓:Can';t调用finish()

Java 安卓:Can';t调用finish(),java,android,android-intent,activity-finish,system.exit,Java,Android,Android Intent,Activity Finish,System.exit,为什么我不能在下面的代码中调用finish()? 我也不能开始任何意图 这是我的代码: public class EditProfilePresenter<V extends EditProfileView> extends PickImagePresenter<V> { protected Profile profile; protected ProfileManager profileManager; protected EditProfil

为什么我不能在下面的代码中调用
finish()
? 我也不能开始任何意图

这是我的代码:

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);
    }
}
公共类EditProfilePresenter扩展了PickImagePresenter{
保护轮廓;
受保护的ProfileManager ProfileManager;
受保护的EditProfilePresenter(上下文){
超级(上下文);
profileManager=profileManager.getInstance(context.getApplicationContext());
}
公共void loadProfile(){
ifViewAttached(BaseView::showProgress);
profileManager.getProfileSingleValue(getCurrentUserId(),新的OnObjectChangedListenerSimple(){
@凌驾
已更改对象的公共无效(配置文件对象){
外形=obj;
ifViewAttached(视图->{
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){
如果(检查InternetConnection()){
ifViewAttached(视图->{
view.setNameError(null);
String name=view.getNameText().trim();
布尔取消=假;
if(TextUtils.isEmpty(name)){
view.setNameError(context.getString(R.string.error_字段_必填));
取消=真;
}如果(!ValidationUtil.isNameValid(name))为else{
view.setNameError(context.getString(R.string.error\u profile\u name\u length));
取消=真;
}
如果(!取消){
view.showProgress();
profile.setUsername(名称);
createOrUpdateProfile(imageUri);
}
});
}
}
私有void createOrUpdateProfile(Uri imageUri){
profileManager.createOrUpdateProfile(配置文件,imageUri,(布尔成功)->{
ifViewAttached(视图->{
view.hideProgress();
如果(成功){
onProfileUpdatedSuccessfully();
//----这里-----
系统出口(0);
//我不能调用finish(),但可以调用System.exit()。
}否则{
view.showSnackBar(R.string.error\u fail\u create\u profile);
}
});
});
}
受保护的void onProfileUpdatedSuccessfully(){
ifViewAttached(BaseView::finish);
}
}

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

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

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

1)为了更快地获得更好的帮助,请添加或。2) 用小写字母输入的单词很难读懂,就像试图听别人喃喃自语一样。请在句子的开头使用大写字母表示单词I,并使用诸如
ArrayList
或Oracle之类的专有名称。3) 在源代码中只需要一行空白就可以了。
{
之后或
}
之前的空行通常也是多余的。感谢您指出,英语不是我的母语,我知道我在这方面有很多错误。您只能在
活动中调用
finish()
。你发布的代码不是一个
活动
@DavidWasser看起来像是答案-不妨这样发布给未来的用户。我知道,我的朋友,我的问题是如何在UP post中的活动完成后循环它以使其完成?1)为了更快地获得更好的帮助,请添加或。2) 用小写字母输入的单词很难读懂,就像试图听别人喃喃自语一样。请在句子的开头使用大写字母表示单词I,并使用诸如
ArrayList
或Oracle之类的专有名称。3) 在源代码中只需要一行空白就可以了。
{
之后或
}
之前的空行通常也是多余的。感谢您指出,英语不是我的母语,我知道我在这方面有很多错误。您只能在
活动中调用
finish()
。你发布的代码不是一个
活动
@DavidWasser看起来像是答案-也可以这样发布给未来的用户。我知道,我的朋友,我的问题是如何在UP post中的活动完成后循环它使其完成?