androidandroid-intentonresume

How transfer data from one app to another app in android


I have two application , com.appone.one and com.apptwo.two.

I want transfer data from appone to apptwo ,I want when a data transferred to apptwo , apptwo opens or if open only come up(onResume) and show that data. I wrote this code:

com.appone.one:

 Intent i = new Intent(Intent.ACTION_DATE_CHANGED);
                    PackageManager manager = getPackageManager();
                    i = manager.getLaunchIntentForPackage("com.apptwo.two");
                    i.putExtra("MessageText",""+Connect.MessageArrive.toString());
                   i.addCategory(Intent.CATEGORY_LAUNCHER); 
startActivity(i);

com.apptwo.two:

@Override
    public void onResume() {
        super.onResume();
        String name=getIntent().getStringExtra("MessageText");
        Toast.makeText(getApplicationContext(),String.valueOf(name), Toast.LENGTH_LONG).show();
    }  

I want only write this line :

String name=getIntent().getStringExtra("MessageText");

in OnResume because I don't want apptwpo load again,If I write this line in onCreate , my code works fine. but I want that in onResume. Now apptwo returns null :(

what should I do? thanks in advance


Solution

  • I solved my problem with this link: http://androiddhamu.blogspot.in/2012/03/share-data-across-application-in.html

    appone:

      SharedPreferences prefs = getSharedPreferences("demopref",
                                 Context.MODE_WORLD_READABLE);
                         SharedPreferences.Editor editor = prefs.edit();
                         editor.putString("demostring", ""+Connect.MessageArrive.toString());
                         editor.commit();
    
                      Intent i = new Intent(Intent.ACTION_DATE_CHANGED);
                        PackageManager manager = getPackageManager();
                        i = manager.getLaunchIntentForPackage("com.graphhopper.android");
                       // i.putExtra("MessageText",""+Connect.MessageArrive.toString());
                       i.addCategory(Intent.CATEGORY_LAUNCHER); 
    
    
                      //i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                        startActivity(i);
    

    apptwo:

      @Override
        public void onResume() {
            super.onResume();
                con = createPackageContext("com.appone.one", 0);
                SharedPreferences pref = con.getSharedPreferences(
                        "demopref", Context.MODE_PRIVATE);
                String data = pref.getString("demostring", "No Value");
    }