Because startActivityForResult can't write in a static class, in order to in other classes call, I can only according to the following method call
Ab test=new ab ();
Test. The DDD ();
Yet tip
: : Attempt to invoke virtual method 'android. The content. The Context android. The content. Context. GetApplicationContext ()' on a null object reference
Ah! Don't know where there are problems
Refer to
StartActivityForResult how to write in a static class?
Or
Ab test=new ab ();
Test. The DDD ();
This call to also go, but it was wrong, can't startActivityForResult new?
Below is the code, thank you help me see
Public class ab extends the Activity {
@ Override
Public void onActivityResult (int requestCode, int the resultCode, Intent data) {
Super. OnActivityResult (requestCode, the resultCode, data);
The d (TAG, "return to normal");
}
Public void DDD () {
Try {
Final MediaProjectionManager mMediaProjectionManager=(MediaProjectionManager) getSystemService (MEDIA_PROJECTION_SERVICE);
Intent captureIntent=mMediaProjectionManager. CreateScreenCaptureIntent ();
StartActivityForResult (captureIntent, 123);
} the catch (Exception e) {
Error Log. D (TAG, ": :" + um participant etMessage ());
e.printStackTrace();
}
}
}
CodePudding user response:
StartActivityForResult (captureIntent, 123);Enforce this prompt error
: : Attempt to invoke virtual method 'android. The content. The Context android. The content. Context. GetApplicationContext ()' on a null object reference
CodePudding user response:
Is this your first time writing an Android? The Activity is to be able to out new? Four components are system management of the Activity to the system process ActivityManagerService. Java via remote RPC calls to create, to create a ActivityThread as its UI main thread, but also create stars for processing handler message loop, but also to bind WindowManagerService with corresponding Activity is used to load the View, moreover ActivityManagerService. Java is also responsible for calling the Activity of a series of life cycle function, you get a new can only ab ordinary objects, rather than an ActivityCodePudding user response:
CodePudding user response:
The Activity is not newWhy in another class called
Can't change the way
In the place where you need to call to Activity to send a message, the Activity is executive startActivityForResult messages are received