There is a scenario in which i need to pass activity and its button to a java class.
I did following and its working fine, I am only concerned if its the right way of integrating this.
MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button= findViewById(R.id.btn);
UIComponents uiComponents= new UIComponents();
uiComponents.setActivity(this, button);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("result", String.valueOf(requestCode));
}
UIComponents.class
public class UIComponents {
public void setActivity(final AppCompatActivity activity, Button btn){
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent= new Intent(activity, ResultActivity.class);
activity.startActivityForResult(intent, 999);
}
});
}
This works perfectly fine, It displays toast
message on my activity screen, also i am able to receive onActivityResult
callback on my activity. I am concerned if this can lead to any performance related issues.