Sending data from the Android library to the main project activity

I am trying to send a string from an Android library to a method in my main project activity. How best can i do it

Here is what I tried

stack overflow

But it gives me this error

java.lang.ClassCastException: zw.com.ianmanda.paynowandroid.PostPayment cannot be added to zw.com.ianmanda.paynowandroid.OnTaskFinishedListener

-2
source share
1 answer
Library Activity:
   try {
                Intent itemintent = null;

                try {
                    itemintent = new Intent(getApplicationContext(), Class.forName("your packagename with class name"));//Ex com.example.test.Activity
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
                Bundle b = new Bundle();
                b.putStringArray("iarray", Array1);
                 b.putString("key", "YourString");
                b.putInt("mflag", 0);
                itemintent.putExtra("android.intent.extra.INTENT", b);
                startActivityForResult(itemintent, 2);
            } catch (Exception e) {
                e.printStackTrace();
            }

In your mainActivity:

     Bundle b =  startingIntent.getBundleExtra("android.intent.extra.INTENT");
if (b != null) {

           String[] strA = b.getStringArray("iarray");
           String value=b.getString("key","")
        }
0
source

Source: https://habr.com/ru/post/1653255/


All Articles