Java 刷新活动而不重新打开?

Java 刷新活动而不重新打开?,java,android,Java,Android,我有一个按钮,用于在特定文件夹中安装从服务器下载的apk文件,用户有时会从文件夹中删除apk文件,但此按钮不会同时禁用,但应退出活动并再次打开。。。我的问题是,在用户删除文件apk后,如何刷新状态按钮,而无需再次打开活动 Button install = (Button) findViewById(R.id.install_font); final File file_1 = new File(Environment.getExternalStorageDirectory()

我有一个按钮,用于在特定文件夹中安装从服务器下载的apk文件,用户有时会从文件夹中删除apk文件,但此按钮不会同时禁用,但应退出活动并再次打开。。。我的问题是,在用户删除文件apk后,如何刷新状态按钮,而无需再次打开活动

 Button install = (Button) findViewById(R.id.install_font);
        final File file_1 = new File(Environment.getExternalStorageDirectory() + "/download/app-debug.apk");
        if(file_1.exists()){
            install.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/"+"app-debug.apk")),
                            "application/vnd.android.package-archive");
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }

            });

        }else {
            install_font.setEnabled(false);
        }

    }
我尝试添加恢复,但始终禁用按钮意味着如果apk文件存在,则该按钮为禁用,apk文件不存在,则该按钮为禁用

 @Override
    public void onResume() {
        super.onResume();

        final File file = new File(Environment.getExternalStorageDirectory() + "/download/app-debug.apk");
        final Button install_font = (Button) findViewById(R.id.install_font);
        install_font.setEnabled(false);
    }

您可以在用户每次进入应用程序时检查您的文件是否存在,然后根据它设置启用标志。 请尝试以下代码:

 @Override
 public void onResume() {
    super.onResume();

    final File file = new File(Environment.getExternalStorageDirectory() + "/download/app-debug.apk");
    final Button install_font = (Button) findViewById(R.id.install_font);
    install_font.setEnabled(file.exists());
}

同样的问题:(如果用户每次再次进入你的应用程序时你的文件都不存在,则该按钮将被禁用。问题是什么?你确定要删除该文件吗?你能更好地解释一下吗?添加@Override public void onResume(){super.onResume()后的问题);如果文件存在或不存在,则按钮始终禁用您是否检查了我的代码?安装_font.setEnabled(file.exists());