Question: How do we call a method located in another activity? For example I'm trying to use this method from the MainActivity public void change
How do we call a method located in another activity?
For example I'm trying to use this method from the "MainActivity"
public void change () {
ConstraintLayout layout = findViewById(R.id.main_layout);
layout.setBackgroundResource(R.drawable.wallpaper);
}
into the second activity (SecondActivity) when clicking a button
I tried this
MainAcitvity MA = new MainActivity();
MA.change();
but it didn't work. what's the correct way to do it in Android?
Step by Step Solution
There are 3 Steps involved in it
In Android you should not instantiate an Activity using new as you did in your example as Activities should be managed by the Android system itself an... View full answer
Get step-by-step solutions from verified subject matter experts
