I suggest passing a parameter to Activity of customers, to know what particular action, for example...
Call for details:
Intent intent = new Intent(activity, ActivityClientes.class);
Bundle bundle = new Bundle();
bundle.putInt("MODO_TELA", ActivityClientes.MODO_DETALHES);
intent.putExtras(bundle);
activity.startActivity(intent);
Call to select the customer:
private static final int IDENTIFICADOR_EXEMPLO = 0;
Intent intent = new Intent(activity, ActivityClientes.class);
Bundle bundle = new Bundle();
bundle.putInt("MODO_TELA", ActivityClientes.MODO_SELECIONAR);
intent.putExtras(bundle);
activity.startActivityForResult(intent, IDENTIFICADOR_EXEMPLO);
in the same Activity implement:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == IDENTIFICADOR_EXEMPLO) {
if(resultCode == RESULT_OK) {
Integer mIdSelect = data.getIntExtra("IdCliente", 0);
//aqui você já tem o idSelecionado
}
}
}
and in your customer’s Activity, treat the "current mode" for example:
public class ActivityClientes extends Activity{
public static final int MODO_DETALHES = 0;
public static final int MODO_SELECIONAR = 1;
private int mModoAtual = -1;
....
@Override
public void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
if (extras.containsKey("MODO_TELA")) {
mModoAtual = extras.getInt("MODO_TELA", -1);
//você tera o "ModoAtual para usar na sua activity para tratar"
//exemplo:
if (mModoAtual == MODO_DETALHES){
//código
}
}
//quando quiser usar o activityForResult, seta o result antes de fechar a tela
private void exemplo(){
if (mModoAtual == MODO_SELECIONAR){
Intent intent = new Intent();
intent.putExtra("IdCliente", 5);
setResult(RESULT_OK, intent);
}
}
//por exemplo no onclick do item da sua listview, faça algo parecido com isso.
public void OnClick(..){
if (mModoAtual == MODO_DETALHES){
//abrir detalhes
}
else if (mModoAtual == MODO_SELECIONAR){
Intent intent = new Intent();
intent.putExtra("IdCliente", idClienteSelecionado);
setResult(RESULT_OK, intent);
finish();
}
}
}
Eai Marco. Dear when I put this code in my main Activity Bundle.putInt("MODO_TELA", Activityclientes.MODO_DETALHES); putInt gives error. And he has no option to solve. You know what ?
– Artur Mafezzoli Júnior
@Arturmafezzolijúnior, did you in your Activity put the constant MODO_DETALHES? You can try replacing it with a fixed value to test, for example Bundle.putInt("MODO_TELA", 0)
– Marco Giovanni
can open the chat here. Because I still have doubts. =(
– Artur Mafezzoli Júnior
I’ll see how you open the chat
– Marco Giovanni
Just walk in here
– Marco Giovanni