How To Send Data Through Intent In Android Without Opening Another Activity?
Solution 1:
Yes i have also faced this problem .
Many developers also facing problems when passing data from dialog to another activity through Intent or Bundle. It returns null at the retrieving time from another activity.
And the only solution is SharedPreferences.
But you have to place it inside the dismiss button.( ex: ok/cancel etc)
And retrieve the data from another activity easily through the same key. Do not use any service followed by broadcast intent .
The code in dialog activity is like this:
AlertDialog.Builderbuilder=newAlertDialog.Builder(this);
builder.setIcon(R.drawable.mailicon);
builder.setTitle(name);
builder.setView(view);
builder.setPositiveButton("Send Request",newDialogInterface.OnClickListener()
{
@OverridepublicvoidonClick(DialogInterface dialog, int which) {
StringmailID= id.getText().toString();
//Here define all your sharedpreferences code with key and valueSharedPreferencesprefs= getSharedPreferences("my_prefs", MODE_PRIVATE);
SharedPreferences.Editoredit= prefs.edit();
edit.putString("MID", mailID );
edit.commit();
}
});
And from another fetch the data like this:
SharedPreferencesbb= getSharedPreferences("my_prefs", 0);
Stringm= bb.getString("NUM", "");
Toast.makeText(this, m, Toast.LENGTH_SHORT).show();
Add some checkings for a good standard.
Thank you
Solution 2:
You call also use SharedPreferences
to archieve that
Solution 3:
You probably want to use a Service
not an activity.
Read: http://developer.android.com/guide/components/fundamentals.html#Components
Post a Comment for "How To Send Data Through Intent In Android Without Opening Another Activity?"