Make an Acitivity on Android appear once only [duplicate]

0

Well, my question is: How do I make an activity appear only once, and then when the user opens the app again this screen does not appear, just the others. I'll explain how my project is to become clearer.

My project is very simple. There are 3 screens, the first one from Cadastro, the second one that is the "main" and the last a recovery screen.

On the first screen the user registers an email and a password. In the second it uses the registered password to be able to Disconnect the phone. And in the last one as I said, it is a password recovery screen.

And I wanted that after the user made the registration on the first screen and was redirected to the second screen, the first screen no longer appears, I just want it to appear once only for the user to register and then no more.

    
asked by anonymous 07.12.2016 / 23:33

2 answers

2

You can do it in two ways ...
One is using SharedPreferences to save a "little tagzinha" and every time you open the app you will have to check if it is there and if it is, do not open the activity. The other way is to save a little tag in sqlite and do the same check, but I do not recommend it. The sharedPreferences looks like this:

    private void setSharedPrefs(Context contexto,
                                       String nomeProjeto,
                                       String chave,
                                       String valor) {
        SharedPreferences sharedPreferences;
        sharedPreferences = contexto.getSharedPreferences(nomeProjeto, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(chave, valor);
        editor.apply();
    }

    private String getSharedPrefs(Context contexto,
                                         String nomeProjeto,
                                         String chave) {
        SharedPreferences sharedPreferences;
        sharedPreferences = contexto.getSharedPreferences(nomeProjeto, Context.MODE_PRIVATE);
        return sharedPreferences.getString(chave, null);
    }

Usage:

        setSharedPrefs(this,"meuProjeto", "meuValor", "HAHAHAHAHA");
        String risada = getSharedPrefs(this,"meuProjeto", "meuValor");
        Log.e("funcionou", risada);

In your case, put it like this on the oncreate of the first activity:

    if(getSharedPrefs(this,"meuProjeto", "meuValor") != null){
       // Se tem algum valor guardado, chama o intent pra trocar de tela
    } else {
        // primeira vez que abriu, então seta o layout normal...
        setContentView(R.id.minhaPrimeiraActivity);
    }
    
08.12.2016 / 13:05
1

In your case the simplest way is to save in SharedPreferences and check if this screen has already been opened for the user.

    
08.12.2016 / 01:08
___ ___ erkimt Message "Invalid object name 'dbo.table' SQL Server Go Lang ______ qstntxt ___

I'm trying to use a select in my SQL Server Database that I own in Azure.

I'm using the Driver: link .

However, I get a message back:

  

mssql: Invalid object name 'dbo.table'.

Below my code, where am I wrong?

%pre%

Return:

  

C: \ Go \ bin \ go.exe run B: \ go \ gocode \ src \ main \ connect-bd.go
  2017/02/25 15:59:33 Main:
  2017/02/25 15:59:33 Opening
  2017/02/25 15:59:33 Opened
  2017/02/25 15:59:33 Pinging
  2017/02/25 15:59:33 Pinged
  2017/02/25 15:59:33 mssql: Invalid object name 'dbo.tbPessoa'.
  exit status 1

    
______azszpr186720___

In my connect string, I was missing out on which bank to use %code%

Done this connected in a good!

Without this information Select was being done in the default SQL master database.

It looks like this:

%pre%     
___ How to put favicon in xml page?