0

I have been trying to send data from my main project to my library project. My library project is defined in main project so no problem of adding dependency of lib project.one more thread I have found similar to my problem but no luck so far...thread

GetUserprofile is the main project's activity and LockscreenActivity is library project's activity.

I have written code on the main project side

Intent myIntent = null;
    try {
        myIntent = new Intent(GetUserprofile.this,LockscreenActivity.class);

       myIntent.putExtra("examiddetails",exam_id);

        startActivity(myIntent);
    } catch (Exception e) {
        e.printStackTrace();
    }

Now I am getting the data which is examiddetails on the library project by using below code

Intent intent = getIntent();    
    try{
        if(intent != null){
            String Examid = intent.getStringExtra("examiddetails");
        }

    }catch(Exception e){
        System.out.println("getdataFromService exception"+e.toString());
    }

I am getting null value of Examid String on the library project.

Vishvendu Palawat
  • 566
  • 10
  • 29

2 Answers2

0

Create Intent From your application

Intent myIntent= new Intent(this,YourActivity.class)
myIntent.putExtra("data", "value");

Get the Intent From Library

string intentdata = ((Activity)getContext()).getIntent().getStringExtra("data");
VenkyDhana
  • 905
  • 5
  • 16
0

Do you mean send data to another activity? I had made same before.

MainProject class

Intent intent= new intent(getApplication(), LockscreenActivity.class);
intent.putExtra("examiddetails",exam_id);
startActivity(intent);

LockscreenActivity class

Bundle bundle = getIntent().getExtras();
String ExamIdDetails = bundle.getString("examiddetails");
Marcel Ruben
  • 81
  • 12
  • I am sending data to library project not into the same project...i guess this works fine when you have two activity in the main project...but i have main project and library project and i have to send data from main project to library project via intent or any other way would be fine – Vishvendu Palawat Jun 07 '17 at 09:04