You can do the following.
In the Manifest add this to the activity tag that will be the Welcome screen.
android:noHistory="true"
This helps if the user presses the back button will not return to the Welcome screen, it would be like this.
<activity
android:name="com.example.example.example.Bienvenida"
android:label="@string/app_name"
android:noHistory="true"
android:theme="@style/AppTheme.NoActionBar"
/>
When executing the application for the first time and pressing the Next button, what we will do is create a Preference. We will create a method.
public void CargarPreferencias(Activity contex, String inicio){
SharedPreferences Preferencias = contex.getSharedPreferences("MisPreferencias", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = Preferencias.edit();
editor.putString("inicio",inicio);
editor.apply();
}
The summary form code would remain so.Activity Welcome.
public class Bienvenida extends AppCompatActivity {
private Button acceder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
acceder = (Button) findViewById(R.id.procesar_login);
assert acceder != null;
acceder.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
/*
Creamos la Preferencia y guardamos el valor del Key inicio=Inciado.
*/
CargarPreferencias(Bienvenida.this,"Inciado");
}
});
}
/*
Creamos la Preferencia y guardamos el valor del Key inicio
*/
public void CargarPreferencias(Activity contex, String inicio){
SharedPreferences Preferencias = contex.getSharedPreferences("MisPreferencias", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = Preferencias.edit();
editor.putString("inicio",inicio);
editor.apply();
}
}
In our Activity Main it would be like this.
public class ActivityMain extends AppCompatActivity {
private Button acceder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
/*Este Metodo es un ciclo de vida de un Activity y se ejecuta justo antes de crear la vista*/
@Override
public void onResume(){
super.onResume();
/*
Verificamos si el user ya vio la Bienvenida si ya la vio no hacemos nada y se muestra el activity Main.
Pero si es la primera vez Llamamos al Activity Bienvenida.
*/
/*si es distinto a Inciado Llamamos a la Presentacion*/
if(!getPreferencia(ActivityMain.this).equals("Inciado")){
Intent acceso = new Intent(this ,Bienvenida.class);
startActivity(acceso);
}
}
/*
Funcion que retorna el valor de la preferencia con key inicio
*/
public String getPreferencia(Activity contex){
SharedPreferences prefs =contex.getSharedPreferences("MisPreferencias",Context.MODE_PRIVATE);
return prefs.getString("inicio","");
}
}