-
check_circle_outlineMódulo 1 | 6 clases
Introducción
expand_more -
check_circle_outlineMódulo 2 | 4 clases
Conceptos Básicos
expand_more -
check_circle_outlineMódulo 3 | 9 clases
Configurando el entorno de trabajo
expand_more -
check_circle_outlineMódulo 4 | 11 clases
Diseño de la aplicación
expand_more -
check_circle_outlineMódulo 5 | 6 clases
Layouts
expand_more -
check_circle_outlineMódulo 6 | 7 clases
Activities
expand_more -
check_circle_outlineMódulo 7 | 10 clases
Componentes Básicos
expand_more -
check_circle_outlineMódulo 8 | 7 clases
Contenedores
expand_more -
check_circle_outlineMódulo 9 | 6 clases
Fechas e Imágenes
expand_more -
check_circle_outlineMódulo 10 | 5 clases
Transiciones
expand_more -
check_circle_outlineMódulo 11 | 5 clases
Advanced y Google
expand_more -
check_circle_outlineMódulo 12.-
Examen del curso
expand_more-
done_all
Examen
Examen final del curso
-
4 comentario(s)
Hola!
Estoy algo confundido con lo sucedido en SingleTask y quisiera que por favor me ayudaran.
En el video se muestra cómo las actividades A y B desaparecen, sin embargo me parece más un coportamiento definido en el Intent que se llama FLAG_ACTIVITY_CLEAR_TOP, ya que por lo que entiendo de la documentación de Android, Single Task no elimina actividades y por el contrario coloca una tarea nueva.
En mi opinón, el resultado debería ser cualquiera de las dos siguientes opciones:
1.
|__A__|
|__B__|
|__A__| |__C__|
Donde el intent se posiciona sobre C.
2.
|__A__| |__C__|
En éste, dado que el Intent recae sobre C automáticamente no hay acceso a A y B.
Quisiera que por favor me ayudaran a resolver mi duda.
Muchas gracias!
Estoy algo confundido con lo sucedido en SingleTask y quisiera que por favor me ayudaran.
En el video se muestra cómo las actividades A y B desaparecen, sin embargo me parece más un coportamiento definido en el Intent que se llama FLAG_ACTIVITY_CLEAR_TOP, ya que por lo que entiendo de la documentación de Android, Single Task no elimina actividades y por el contrario coloca una tarea nueva.
En mi opinón, el resultado debería ser cualquiera de las dos siguientes opciones:
1.
|__A__|
|__B__|
|__A__| |__C__|
Donde el intent se posiciona sobre C.
2.
|__A__| |__C__|
En éste, dado que el Intent recae sobre C automáticamente no hay acceso a A y B.
Quisiera que por favor me ayudaran a resolver mi duda.
Muchas gracias!
Es mucho más conciso y los invito a probarlo en caso de que no puedan con el compartido por github. Además de lo aprendido hasta el momento deberán saber que usan la etiqueta include para que cada Activity posea los mismos botones A, B, C y D además del texto. De igual forma es mucho más específico en cuanto a los estados del Activity.
Saludos!
<activity android:name=".A" android:label="Label A" android:launchMode="standard">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".B" android:label="Label B" android:launchMode="singleTop"/>
<activity android:name=".C" android:label="Label C" android:launchMode="singleTask"/>
<activity android:name=".D" android:label="Label D" android:launchMode="singleInstance"/>
public class VerificadorEstado extends AppCompatActivity implements View.OnClickListener {
protected StringBuilder texto;
protected TextView textViewTexto;
public void imprimirEstado(String estado) {
texto.append(this.getClass().getSimpleName() + ": " + estado + "\n");
textViewTexto.setText(texto.toString());
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
switch (this.getClass().getSimpleName()) {
case "A" :
setContentView(R.layout.activity_a);
break;
case "B" :
setContentView(R.layout.activity_b);
break;
case "C" :
setContentView(R.layout.activity_c);
break;
case "D" :
setContentView(R.layout.activity_d);
break;
}
this.texto = new StringBuilder();
this.textViewTexto = (TextView) findViewById(R.id.textViewTexto);
imprimirEstado("Create");
findViewById(R.id.btnA).setOnClickListener(this);
findViewById(R.id.btnB).setOnClickListener(this);
findViewById(R.id.btnC).setOnClickListener(this);
findViewById(R.id.btnD).setOnClickListener(this);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
imprimirEstado("NewIntent");
}
@Override
protected void onStart() {
super.onStart();
imprimirEstado("Start");
}
@Override
protected void onResume() {
super.onResume();
imprimirEstado("Resume");
}
@Override
protected void onPause() {
super.onPause();
imprimirEstado("Pause");
}
@Override
protected void onStop() {
super.onStop();
imprimirEstado("Stop");
}
@Override
protected void onRestart() {
super.onRestart();
imprimirEstado("Restart");
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnA:
abrirActividad(A.class);
break;
case R.id.btnB:
abrirActividad(B.class);
break;
case R.id.btnC:
abrirActividad(C.class);
break;
case R.id.btnD:
abrirActividad(D.class);
break;
}
}
public void abrirActividad(Class c){
startActivity(new Intent(getApplicationContext(),c));
}
}
template01.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">\
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100"
android:orientation="horizontal"
>
<TextView
android:id="@+id/textViewTexto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="100"
android:text=""
android:textAlignment="center"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
>
<Button
android:id="@+id/btnA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="25"
android:text="A" />
<Button
android:id="@+id/btnB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="25"
android:text="B" />
<Button
android:id="@+id/btnC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="25"
android:text="C" />
<Button
android:id="@+id/btnD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="25"
android:text="D" />
</LinearLayout>
</merge>
En cada Activity de a, b, c y d colocan esto:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/template01"/>
</RelativeLayout>
Espero les funcione!
Saludos!
<activity android:name=".A" android:label="Label A" android:launchMode="standard">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".B" android:label="Label B" android:launchMode="singleTop"/>
<activity android:name=".C" android:label="Label C" android:launchMode="singleTask"/>
<activity android:name=".D" android:label="Label D" android:launchMode="singleInstance"/>
public class VerificadorEstado extends AppCompatActivity implements View.OnClickListener {
protected StringBuilder texto;
protected TextView textViewTexto;
public void imprimirEstado(String estado) {
texto.append(this.getClass().getSimpleName() + ": " + estado + "\n");
textViewTexto.setText(texto.toString());
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
switch (this.getClass().getSimpleName()) {
case "A" :
setContentView(R.layout.activity_a);
break;
case "B" :
setContentView(R.layout.activity_b);
break;
case "C" :
setContentView(R.layout.activity_c);
break;
case "D" :
setContentView(R.layout.activity_d);
break;
}
this.texto = new StringBuilder();
this.textViewTexto = (TextView) findViewById(R.id.textViewTexto);
imprimirEstado("Create");
findViewById(R.id.btnA).setOnClickListener(this);
findViewById(R.id.btnB).setOnClickListener(this);
findViewById(R.id.btnC).setOnClickListener(this);
findViewById(R.id.btnD).setOnClickListener(this);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
imprimirEstado("NewIntent");
}
@Override
protected void onStart() {
super.onStart();
imprimirEstado("Start");
}
@Override
protected void onResume() {
super.onResume();
imprimirEstado("Resume");
}
@Override
protected void onPause() {
super.onPause();
imprimirEstado("Pause");
}
@Override
protected void onStop() {
super.onStop();
imprimirEstado("Stop");
}
@Override
protected void onRestart() {
super.onRestart();
imprimirEstado("Restart");
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnA:
abrirActividad(A.class);
break;
case R.id.btnB:
abrirActividad(B.class);
break;
case R.id.btnC:
abrirActividad(C.class);
break;
case R.id.btnD:
abrirActividad(D.class);
break;
}
}
public void abrirActividad(Class c){
startActivity(new Intent(getApplicationContext(),c));
}
}
template01.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">\
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100"
android:orientation="horizontal"
>
<TextView
android:id="@+id/textViewTexto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="100"
android:text=""
android:textAlignment="center"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
>
<Button
android:id="@+id/btnA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="25"
android:text="A" />
<Button
android:id="@+id/btnB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="25"
android:text="B" />
<Button
android:id="@+id/btnC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="25"
android:text="C" />
<Button
android:id="@+id/btnD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="25"
android:text="D" />
</LinearLayout>
</merge>
En cada Activity de a, b, c y d colocan esto:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/template01"/>
</RelativeLayout>
Espero les funcione!
quiero poder practicar mejor esta parte de los lanzamientos de una activity, podrían facilitar el código para entender como aplicarlo
Clase 39