java - Launching intent from a class outside an activity -
I have two activities, one of them is called MyActivity
. I want both of them to be able to use the functions located in a class that we can call on MyClass
In MyClass
, I get the activity to other I try to use the intent to launch the activity
. Since the constructor takes a reference in the form of parameters, I used to try to store a reference from the activity in the constructor, and then use it when I try to make my intention.
class MyClass {Personal Context CXT; Myclass (reference CSTT) {this.cxt = cxt; } StartIntent () {intention intended = new intention (CETT, other activity class); StartActivity; // This line throws a NullPointerException}}
MyActivity
code to use the class is shown below:
MyClassObject = new MyClass (MyActivity.This); MyClassObject.startIntent (); However, even no logic is understood that there is no logic (a simple statement is checked), intent
redundant and a NullPointerException
Throwed, why does not this work, and what can I do to solve the problem? I am new to Android and Java development, so please explain it as basic as possible.
cxt.start activity (new intent (CETT, other specialty class));
And to make sure that its intention is taped, and some are not internally in the beginning, you can add some checks, i.e.
Intent to intent = new intent (CCTT, other specialty class); Log D. (Tosting ()), "intent =" + intent.Tastring ()); Cxt.startActivity;
Comments
Post a Comment