Search code examples
androidandroid-intentandroid-activitybundle

send data from activity to another without start it


If I have two activities Activity1 and Activity2 and I want to send data from Activity1 to Activity2 without Start Activity2

I know if I want to start Activity2 I use this code in Activity1.java

Intent intent ;
Bundle bundle = new Bundle();

bundle.putString(BG_SELECT, hexColor);

intent = new Intent(getApplicationContext(), Activity2.class);

intent.putExtras(bundle);

// this is to start but I want just refresh Activity2 not start it
startActivityForResult(intent, uniqueNo);

and in Activity2.java

bundle = getIntent().getExtras();

if (bundle != null) {
   bgColor = bundle.getString(SebhaActivity.BG_SELECT);
   System.out.println("in Activity2, selected BG: "+bgColor);

}

How to refresh Activity2 to find data in it without Start it? Thanks in Advance.


Solution

  • if the next activity (where you need data, Activity2 i.e) wont start from here you can save the data in SharedPreferences in Activity 1 and access it in activity2 when you get there