Tecnologia do Blogger.
RSS

Re: [androidbrasil-dev] Eliminar Activities da pilha

Olá Gink,

Tive que fazer um SAIR da aplicação, que é exatamente o que está tentando fazer, conseguir implementar mas não sei se é a forma mais elegante, mas de qualquer forma estou postando o código para você conferir:



O apps possui A1, A2, A3 Activity.
Todas as Activity possui o button SAIR.

Arquivo A1

No A1 no OnCreate possui:
if( getIntent().getBooleanExtra("

EXIT", false )){

    finish();
 
  ///disparando para ir para o HOME
  Intent intent = new Intent(Intent.ACTION_MAIN);
  intent.addCategory(Intent.CATEGORY_HOME);
  intent.addFlags(tela2.FLAG_ACTIVITY_CLEAR_TOP | tela2.FLAG_ACTIVITY_SINGLE_TOP);
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  startActivity(intent);
  ///fim
}

O evento onClick SAIR:
tela2.putExtra("EXIT", true );
startActivity( tela2 );

No OnRestart possui:
tela1 = new Intent(this, MainActivity.class);
startActivity( tela1 );

Arquivo A2

No A2 no OnCreate possui:
if (getIntent().getBooleanExtra("EXIT", false)) {
  tela1.putExtra("EXIT", true );

  startActivity( tela1 );
  finish();
}

No evento onClick SAIR:
 tela1.putExtra("EXIT", true );
 startActivity( tela1 );
 finish();

No onRestart possui:
tela1 = new Intent(this, MainActivity.class);
startActivity( tela1 );


Arquivo A3

No A3 no OnCreate possui:
if (getIntent().getBooleanExtra("EXIT", false)) {
  tela2.putExtra("EXIT", true );

  startActivity( tela2 );
  finish();
}

No evento onClick SAIR:
tela2.putExtra("EXIT", true );
startActivity( tela2 );
finish();

No onRestart possui:
tela1 = new Intent(this, MainActivity.class);
startActivity( tela1 );




Em sexta-feira, 24 de maio de 2013 23h22min25s UTC-3, Gink Labrev escreveu:
Pessoal,

Ao chamar a Activity B, preciso eliminar todas existente na pilha, ficando somente esta.

Então faço o seguinte:

Intent intent = new Intent(A.this, B.class);
intent.addFlags(
    Intent.FLAG_ACTIVITY_CLEAR_TOP |
    Intent.FLAG_ACTIVITY_SINGLE_TOP |
    Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

Mas ainda assim não funciona.
Alguém sabe o que ocorre ?

Abs,

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentários:

Postar um comentário