提示输入用户名时,应用程序启动,下一次他启动应用程序问候用户 [英] Prompt for username when application starts and greet the user the next time he launches the app

查看:101
本文介绍了提示输入用户名时,应用程序启动,下一次他启动应用程序问候用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个Android应用程序,需要我来提示用户输入他的名字第一次在用户启动应用程序。在第二次起,应用程序将不会提示输入自己的名字的用户,而不是将迎接用户,而不是(并马上进入主菜单页面。有谁知道我怎么可以这样做?

I'm building an android app which requires me to prompt the user for his name the first time the user launches the app. During the second time onwards, the application won't prompt the user for his name instead it will greet the user instead(and straight away go to the main menu page. Does anybody know how I might do this?

推荐答案

使用这种code:

        File file = new File("username.txt");

        // if file doesnt exists, then prompt username alert dialog
        if (!file.exists()) {
          //prompt for username
          file.createNewFile();
        }

        FileWriter fw = new FileWriter(file.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);
        //suppose  EditText_UserName is your edittext where he can enter his name
        bw.write(EditText_UserName.getText().toString());
        bw.close();

每当你启动应用程序,检查该文件使用file.exists并继续。

Everytime you start the application, check for this file using file.exists and continue.

这篇关于提示输入用户名时,应用程序启动,下一次他启动应用程序问候用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆