How to send data using intent to android without opening another action?

here is my code to send data by intent, but I don’t want to open another action, I just want to send data without opening it.

Bundle contain = new Bundle(); contain.putString("key4", item); contain.putString("price", price); Intent a = new Intent(Searchbydate.this, Searchbyitem.class); a.putExtras(contain); startActivity(a); 

here I do not want to open this Searchbyitem.class, just send the data ...

+7
source share
4 answers

You also call SharedPreferences for archiving.

+3
source

Yes, I also ran into this problem.

Many developers also encounter problems transferring data from the dialogue to another activity via Intent or Bundle. It returns null when it is received from another action.

And the only solution is SharedPreferences.

But you have to put it in the dismiss button (for example: ok / cancel, etc.)

And it's easy to get data from another activity through the same key. Do not use a service followed by a broadcast intent.

The code in the dialog operation is as follows:

  AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setIcon(R.drawable.mailicon); builder.setTitle(name); builder.setView(view); builder.setPositiveButton("Send Request",new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String mailID = id.getText().toString(); //Here define all your sharedpreferences code with key and value SharedPreferences prefs = getSharedPreferences("my_prefs", MODE_PRIVATE); SharedPreferences.Editor edit = prefs.edit(); edit.putString("MID", mailID ); edit.commit(); } }); 

And from another, select the following data:

  SharedPreferences bb = getSharedPreferences("my_prefs", 0); String m = bb.getString("NUM", ""); Toast.makeText(this, m, Toast.LENGTH_SHORT).show(); 

Add some checks for a good standard.

thanks

+3
source

You probably want to use Service not an action.

Read: http://developer.android.com/guide/components/fundamentals.html#Components

+1
source

You can try the EventBus or Otto Android libraries to communicate between actions, services, and fragments.

So, you must create a Service for data transfer and for communication between actions, fragments, etc., using the event bus

+1
source

All Articles