One practice that I use a lot in my projects is to create Uteis
classes to center all result_code
and messages between Activity
An example
public class Prefs {
public static final String PHOTO_PATH = "photo_path";
public static final String AUDIO_PATH = "audio_path";
public static final String COMMENTARY = "commentary";
}
Now, sending to your Activity
via try and getting in another Activity
:
Intent intent = new Intent(this, SuaActivity.class);
intent.putExtra(Prefs.PHOTO_PATH , photo_path);
intent.putExtra(Prefs.AUDIO_PATH , audio_path);
intent.putExtra(Prefs.COMMENTARY , commentary);
startActivity(intent);
...
if (getIntent().getExtras() != null) {
String photo_path= getIntent().getExtras().getString(Prefs.PHOTO_PATH, "");
String audio_path = getIntent().getExtras().getString(Prefs.AUDIO_PATH, "");
String commentary = getIntent().getExtras().getString(Prefs.COMMENTARY, "");
}
You can also do this to center reques_code
on startActivityForResult
, for example:
public class RequestCode{
public static final int UMA_ACAO = 0;
public static final int OUTRA_ACAO = 1;
public static final int MAIS_UMA_ACAO = 2;
}
And on your Activity
Intent intent = new Intent(this, SuaActivity.class);
intent.putExtra(Prefs.PHOTO_PATH , photo_path);
intent.putExtra(Prefs.AUDIO_PATH , audio_path);
intent.putExtra(Prefs.COMMENTARY , commentary);
startActivityForResult(intent, RequestCode.UMA_ACAO );
...
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RequestCode.UMA_ACAO)
//fazer algo
else if (requestCode == RequestCode.OUTRA_ACAO)
//fazer algo
else if (requestCode == RequestCode.MAIS_UMA_ACAO)
//fazer algo
super.onActivityResult(requestCode, resultCode, data);
}