I have an instance of an object created in my onCreate in my main android project. I have created a menu item which is outside of the menu item but I want to access the same instance. How do I do this? (I can’t make the instance global since the onCreate would not have been called yet.
public class My_Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my__main);
final new_viewer pv = new new_viewer(this);
}
}
public void test()
{
//how can I get the same instance of pv here?
}
Any help with this is greatly appreciated.
Thanks!
Make your
private new_viewer pv;as Class Level Variable forMy_Main Activity, like,Also Put your
test()function inside of My_Main Activity scope..