I am developing an library for Android and have following scenario, I want a response back to MainActivity. How could I do it? I have tried with callbacks but could not as I could not create an object of Activity class by myself. is there any other way to achieve it? in AsyncTaskListener implementation I am doing some network operation. I could not use startActivityForResult as it's not according to my library specification.
public class MainActivity extends AppCompatActivity implements MyReceiver{
@Override
protected void onCreate(Bundle savedInstanceState) {
MyServiceImpl b = new MyServiceImpl();
String request = "123";
b.request(this,request);
}
@Override
public void completed(String result) {
Log.d("MainActivity","Result - "+result);
}
}
public class MyServiceImpl{
public void request(Activity appActivity,String req){
Intent intent = new Intent(appActivity, ActivityB.class);
appActivity.startActivity(intent);
}
}
public class ActivityB extends AppCompatActivity imnplements AsyncTaskListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
// shows UI
// network operations
}
@Override
public void taskFinish(String response) {
// my result comes here
// now i want this result to propagated to MainActiviy
}
}