i use xamarin monogame , need run android activity c# code. try this:
public class test : activity { public void start() { startactivity(typeof(myactivity)); } } } then update() calling start().
protected override void update(gametime gametime) { ... test test = new test(); test.start(); ... } but have error. me, please
an existing activity instance has bit of work goes on behind scenes when it's constructed; activities started through intent system (all activities) have context reference added them when instantiated. context reference used in call-chain of startactivity.
so, java.lang.nullpointerexception seen after invoking startactivity on test activity instance because context inside instance has never been set. using new operator create activity instance you've circumvented normal way activities instantiated, leaving instance in invalid state!
this can fixed using global application context launch activity:
var intent = new intent(android.app.application.context, typeof(test)); intent.setflags(activityflags.newtask); android.app.application.context.startactivity (intent);
Comments
Post a Comment