app crash with android.content.Context.getPackageName()' on a null object reference - java

i need help.
I'm in the finish phase of development of my android application and now after a few month of develop the app magically crash with this error :
java.lang.String android.content.Context.getPackageName()' on a null object reference
I don't know what is the problem but i will post the code that cause the crash :
public static void start(Context context) {
context.startActivity(new Intent(context, ConversationsActivity.class));
}
called with this piece of code (inside a fragment):
ConversationsActivity.start(getActivity());
The last change that i've make was to add Fabric.io ( in particular Branch ) and from the history in the last commit on git i don't show nothing that can produce this error
EDIT :
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
at android.content.ComponentName.<init>(ComponentName.java:128)
at android.content.Intent.<init>(Intent.java:4900)
at com.exampleapp.views.messages.ConversationsActivity.start(ConversationsActivity.java:31)
at com.exampleapp.views.menu.MenuFragment.onMenuMessagesClicked(MenuFragment.java:116)
at com.exampleapp.views.menu.MenuFragment_ViewBinding$5.doClick(MenuFragment_ViewBinding.java:82)
at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

Or you could do this:
public static void start(Activity activity) {
activity.startActivity(new Intent(activity, ConversationsActivity.class));
}

You should use getActivity() to launch an Activity from Fragment.
From a Fragment: Context is parent activity (getActivity()).
Intent intent = new Intent(getActivity(), ConversationsActivity.class);
startActivity(intent);
From an Activity: Context is current activity (this).
Intent intent = new Intent(this, ConversationsActivity.class);
startActivity(intent);

Your problem is that you are using the intent wrong. Replace your start() code with this:
public static void start() {
Intent i = new Intent(getApplicationContext(), ConversationsActivity.class);
startActivity(i);
}
Then instead of using ConversationsActivity.start(getActivity()); to call it, just use start(); when you want to call the method.
Hope this helps!

Related

Two exact same startactivity() in a switch, only one works

I'm new at coding.
So I have a switch where the app can choose the next actvity using the string nextActivityExtra. The intent.putExtra are necessary for the other activities and no activity have problem recieving them. So basically the code works, but only on the first case. When the app comes back at this "switch activity", it should get to the second case, and here it cannot load MainActivity (it loads a black screen and suddenly goes back to the "switch activity").
If I switch ExplicaioActivity for MainActivity or for any other activty it will work fine unless it's in the second case. I really cannot grasp what's happening here, I also tried the same code with If's with similar results.
public class EntreActivities extends AppCompatActivity {
ImageView iconView;
int count;
String levelExtra;
Intent intent;
String nextActivityExtra;
String rutaLevelNumber;
boolean isTaskCompleted;
Class myClass;
public void Rotate(View view) {
RotateAnimation rotateAnimation = new RotateAnimation(0, 30,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 1f);
rotateAnimation.setDuration(3000);
rotateAnimation.setRepeatMode(Animation.REVERSE);
rotateAnimation.setRepeatCount(Animation.INFINITE);
rotateAnimation.setFillAfter(true);
rotateAnimation.setStartOffset(1000);
iconView.setAnimation(rotateAnimation);
}
public void startAct() {
if (getIntent().getBooleanExtra("inTraining", false)) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
Toast.makeText(this, "TTTTtrain", Toast.LENGTH_SHORT).show();
} else {
switch (nextActivityExtra) {
case "ExplicaioActivity":
myClass = ExplicaioActivity.class;
Toast.makeText(EntreActivities.this, "here", Toast.LENGTH_SHORT).show();
intent = new Intent(getApplicationContext(), ExplicaioActivity.class);
intent.putExtra("Level", rutaLevelNumber);
intent.putExtra("inTraining", false);
startActivity(intent);
overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);
break;
case "MainActivity":
myClass = MainActivity.class;
Toast.makeText(EntreActivities.this, "here", Toast.LENGTH_SHORT).show();
intent.putExtra("Level", rutaLevelNumber);
intent.putExtra("inTraining", false);
intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);
break;
}
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_entre_activities);
iconView = findViewById(R.id.iconView);
iconView.setRotation(-15);
Intent intent = getIntent();
levelExtra = intent.getStringExtra("Level");
nextActivityExtra = intent.getStringExtra("NextActivity");
rutaLevelNumber = intent.getStringExtra("Level");
Rotate(iconView);
startAct();
}
}
This is the error log that I could take from AS:
2019-01-12 01:08:12.383 4282-4282/com.example.root.exercicis E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.root.exercicis, PID: 4282
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.root.exercicis/com.example.root.exercicis.EntreActivities}: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
at com.example.root.exercicis.EntreActivities.startAct(EntreActivities.java:53)
at com.example.root.exercicis.EntreActivities.onCreate(EntreActivities.java:100)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 
you are trying to put extra before initialising the Intent inside MainActivity case.
Initialize Intent before putting extra like following
intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra("Level", rutaLevelNumber);
intent.putExtra("inTraining", false);
The reason for this is because you're creating a new Intent that doesn't have the String extra "NextActivity".
Let me walk you through what's happening:
Activity is started and onCreate() is run.
Intent intent = getIntent() is run and intent now contains all data from the Intent that was sent to this Activity.
nextActivityExtra = intent.getStringExtra("NextActivity") is run and now, nextActivityExtra is now stored with either "ExplicaioActivity" or "MainActivity".
startAct() is run.
Switch statement is run properly because nextActivityExtra has the proper value. Let's pretend it's ExplicaioActivity.
intent = new Intent(getApplicationContext(), ExplicaioActivity.class);is run, and it creates a NEW intent.
You use intent.putExtra("Level") and intent.putExtra("inTraining"), but forget to put `intent.putExtra("NextActivity");
New Activity is started and onCreate() is run.
Intent intent = getIntent() is run and intent now contains all data from the Intent that was sent to this Activity. But keep in mind that this Intent from the previous Activity is missing the Extra "NextActivity"
nextActivityExtra = intent.getStringExtra("NextActivity") is run, but since there's no extra for this, so null is stored in this variable instead.
Switch case happens, but Switch does not support null so the black screen is actually a crash for the Activity.
So to fix this, you simply have to add intent.putExtra("NextActivity", NEW_VALUE); inside case "ExplicaioActivity" with NEW_VALUE being the new value you want to add as the extra value. `
However, for case "MainActivity", besides doing what I said before, you also need to rearrange a line of code.
Switch this:
intent.putExtra("Level", rutaLevelNumber);
intent.putExtra("inTraining", false);
intent = new Intent(getApplicationContext(), MainActivity.class);
to this:
intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra("Level", rutaLevelNumber);
intent.putExtra("inTraining", false);

NullPointerException while dealing with creating an intent in MainActivity [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 5 years ago.
I've been looking into this for a few days and can't seem to find a thread specific to my problem. My app crashes every time I try to add a string to my bundle.
I'm getting the error at extras.putString(EXTRA_MESSAGE, message);
MainActivity.java
public class MainActivity extends AppCompatActivity {
private ArrayList<String> priceGroupSpinnerItems;
public static final String EXTRA_MESSAGE = "lss.mywebsiteoffline.MESSAGE";
public String message = "";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spnPriceGroup = (Spinner) findViewById(R.id.price_group_spinner);
ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.list_price_group, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spnPriceGroup.setAdapter(adapter);
message = spnPriceGroup.getSelectedItem().toString();
}
/** Called when the user taps the Go button */
public void sendMessage(View view) {
Intent mIntent;
mIntent = new Intent(this, nextActivity.class);
Bundle extras = mIntent.getExtras();
extras.putString(EXTRA_MESSAGE, message);
mIntent.putExtras(extras);
startActivity(mIntent);
}
}
Logcat
E/AndroidRuntime: FATAL EXCEPTION: main
Process: lss.mybbofflinever3, PID: 8181
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5702)
at android.widget.TextView.performClick(TextView.java:10896)
at android.view.View$PerformClick.run(View.java:22546)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5702) 
at android.widget.TextView.performClick(TextView.java:10896) 
at android.view.View$PerformClick.run(View.java:22546) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:158) 
at android.app.ActivityThread.main(ActivityThread.java:7224) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.Bundle.putString(java.lang.String, java.lang.String)' on a null object reference
at lss.mywebsiteoffline.MainActivity.sendMessage(MainActivity.java:59)
I have tried examples to use just intent, or bundle, and adding strings directly to putString. I might be missing something blatantly obvious. Not sure what I might be looking for after adding strings directly to the putString method and getting the same error.
By default an Intent does not have extras and getExtras() returns null. If you want to set extras, you need to create the extras bundle yourself. Replace
Bundle extras = mIntent.getExtras();
with
Bundle extras = new Bundle();
Or just call one of the putExtra() overloads on the Intent - it will also init the extras bundle in case it's not there already.
Try this:
Intent mIntent = new Intent(this, nextActivity.class);
mIntent.putExtra(EXTRA_MESSAGE, message);
startActivity(mIntent);

Context for intent in onpostexecute is not null but getting null exception

I've been stumped with this problem for two days now. I've checked this forum and other forums but can't get a question or answer close enough to my problem.
Basically I'm trying to execute an intent to open an activity from a non-activities onpostexecute, I'm sending the context (MainActivty.this) and string from a onMarkerClick function that is in a method in the MainActivity. This is going to a constructor in the non-activity which has the parameters for context and the string.
The issue is that I'm getting a null exception, but after debugging, the context is not null, it has the value of MainActivity, but when the intent is executed it returns a null exception. I've also tried many variations eg. Activity, getApplicationContext, this.context, (classname).context, (classname).this and tried a global context to no avail. The odd thing is I put the intent into an if statement if(context != null) and it passes through and it executes the intent which in turn gives me null exception which doesn't make sense. I know I'm new to android if anyone has any other suggestions on opening the activity that would be great thanks very much.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.quantusapps.joggertest, PID: 12253
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
at android.content.ContextWrapper.getPackageName(ContextWrapper.java:131)
at android.content.ComponentName.(ComponentName.java:77)
at android.content.Intent.(Intent.java:4029)
at com.example.quantusapps.joggertest.BusCoachTramInfo.onPostExecute(BusCoachTramInfo.java:131)
at com.example.quantusapps.joggertest.BusCoachTramInfo.onPostExecute(BusCoachTramInfo.java:25)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5696)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)<
This is the Mainactivity Method with onMarkerClick
mGoogleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
String bctID = bctExtraMarkerInfo.get(marker.getId());
BusCoachTramInfo busCoachTramInfo = new BusCoachTramInfo(bctID, MainActivity.this);
busCoachTramInfo.execute(bctID);
return false;
}
});
This is the non-activity constructor.
Context context;
BusCoachTramInfo(String busstopID, Context context) {
this.context = context;
naptanIdUrl = "https://api.tfl.gov.uk/StopPoint/" + busstopID + "/Arrivals?app_key=" + tfl_API_KEY + "&app_id=9c0b3009";
}
This is where the null exception is happening.
#Override
protected void onPostExecute(TreeMap<Integer, String[]> Map) {
super.onPostExecute(Map);
Intent i = new Intent(context, BusArrivalTime.class);
context.startActivity(i);
One way to get things done is implementing the AsyncTask as part of a method which takes an instance of MainActivity as a parameter. The AsyncTask on the other hand would work with a WeakReference:
void doExecuteBusCoachTramInfo(final String busstopID, MainActivity activity){
final WeakReference<MainActivity> wrActivity = new WeakReference<MainActivity>(MainActivity.this);
new AsyncTask<Void, Void, TreeMap<Integer, String[]>>(){
#Override
protected TreeMap<Integer, String[]> doInBackground(Void... params)
{
// your code from BusCoachTramInfo here
}
#Override
protected void onPostExecute(TreeMap<Integer, String[]> integerTreeMap)
{
// get back to the original Activity if possible:
MainActivity activity = wrActivity.get();
if (activity != null){
Intent i = new Intent(activity, BusArrivalTime.class);
activity.startActivity(i);
}
}
}.execute();
}
This method may be part of MainActivity, but it can just as well belong to some other class.

Start another activity in another class

I have a three class: MainActivity, BackgroundActivity and roomActivity.
BackgroundActivity will receipt the php server feedback.
If it is not login fail, it will call RoomActivity class.
I want to know that why is not functioning?
BackgroundActivity:
protected void onPostExecute(String result) {
if (result.equals("<meta charset=\"utf-8\">login fail")) {
alertDialog.setMessage("Please check your login email");
alertDialog.show();
} else {
**Intent myIntent = new Intent(MainActivity.class, RoomActivity.class);
startActivity(myIntent);**
}
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.a20_1discussboard, PID: 2262
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
at android.content.ContextWrapper.getPackageName(ContextWrapper.java:132)
at android.content.ComponentName.<init>(ComponentName.java:77)
at android.content.Intent.<init>(Intent.java:4160)
at com.example.a20_1discussboard.MainActivity.check(MainActivity.java:38)
at com.example.a20_1discussboard.BackgroundWorker.onPostExecute(BackgroundWorker.java:151)
at com.example.a20_1discussboard.BackgroundWorker.onPostExecute(BackgroundWorker.java:24)
at android.os.AsyncTask.finish(AsyncTask.java:636)
at android.os.AsyncTask.access$500(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:653)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
change it to
Intent myIntent = new Intent(MainActivity.this, RoomActivity.class);
Calling startActivity() from outside of an Activity may produce AndroidRuntimeException, Use Context like:
Intent myIntent = new Intent(MainActivity.class, RoomActivity.class);
getApplicationContext().startActivity(myIntent);
Intent constructor is wrong.
it should be like :
Intent myIntent = new Intent(getApplicationContext(), RoomActivity.class);
startActivity(myIntent);
could you post more info about the issue ?

android.app.ActivityThread.getApplicationThread()' on a null object reference

The microhonePopUp method will work in MainActivity, but I'd like for it to work from another class (MediaButtonIntentReceiver). The problem is with startActivityForResult(intent, REQUEST_CODE); - but I don't know how to resolve it.
in the MainActivity class
public void microphonePopUp(){
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice your answer");
startActivityForResult(intent, REQUEST_CODE);
}
in the MediaButtonIntentReceiver class
public class MediaButtonIntentReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
KeyEvent event = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (KeyEvent.KEYCODE_HEADSETHOOK == event.getKeyCode()) {
MainActivity test = new MainActivity();
test.microphonePopUp();
}
}
}
}
12-09 11:20:14.803 19556-19556/com.timtennyson.priceaddition
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.timtennyson.priceaddition, PID: 19556
java.lang.RuntimeException: Unable to start receiver
com.timtennyson.priceaddition.MediaButtonIntentReceiver:
java.lang.NullPointerException: Attempt to invoke virtual method
'android.app.ActivityThread$ApplicationThread
android.app.ActivityThread.getApplicationThread()' on a null object
reference
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3641)
at android.app.ActivityThread.access$2000(ActivityThread.java:221)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1876)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual
method 'android.app.ActivityThread$ApplicationThread
android.app.ActivityThread.getApplicationThread()' on a null object
reference
at android.app.Activity.startActivityForResult(Activity.java:4283)
at android.app.Activity.startActivityForResult(Activity.java:4230)
at
android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:842)
at
com.timtennyson.priceaddition.MainActivity.microphonePopUp(MainActivity.java:103)
at
com.timtennyson.priceaddition.MediaButtonIntentReceiver.onReceive(MediaButtonIntentReceiver.java:27)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3634)
at android.app.ActivityThread.access$2000(ActivityThread.java:221) 
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1876) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:158) 
at android.app.ActivityThread.main(ActivityThread.java:7224) 
at java.lang.reflect.Method.invoke(Native Method)
NEVER create an instance of an activity, service, or provider yourself.
If your objective is to listen for ACTION_MEDIA_BUTTON broadcasts while MainActivity is visible:
Move MediaButtonIntentReceiver to be a nested class inside of MainActivity
Get rid of test from onReceive(), and just call microphonePopUp() (which I assume is a method on MainActivity)
Register your MediaButtonIntentReceiver using registerReceiver() in onStart() of MainActivity, and use unregisterReceiver() in onStop()
If your objective is to listen ACTION_MEDIA_BUTTON broadcasts at other points in time — by registering your receiver in the manifest — while you can do that, you cannot use microphonePopUp() from that receiver.

Categories