Error recieveing broadcast Intent when resuming MainActivity

M Micheal Sadleir 2 years 11 months ago
300 2 0

Hi,
 
I have an app that takes a scan in the MainActivity passed it to an async task that starts a new activity (BroadcastIntentActivity) when it completes. When I finish the data processing in BroadcastIntentActivity I want to resume the MainActivity but I get this error. The code in BroadcastIntentActivity I use to start MainActivity is context.startActivity(new Intent(context, MainActivity.class));
 
    03-02 09:02:59.198    2430-2430/com.example.michealsadleir.emdksamplebase E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.michealsadleir.emdksamplebase, PID: 2430
    java.lang.RuntimeException: Error receiving broadcast Intent { act=com.symbol.emdksample.RECVRBI flg=0x10 (has extras) } in com.example.michealsadleir.emdksamplebase.BroadcastIntentActivity$1@41b5e690
            at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:769)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5045)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at android.content.ComponentName.(ComponentName.java:77)
            at android.content.Intent.(Intent.java:3838)
            at com.example.michealsadleir.emdksamplebase.BroadcastIntentActivity.onNoItemsLeft(BroadcastIntentActivity.java:389)
            at com.example.michealsadleir.emdksamplebase.BroadcastIntentActivity$1.onReceive(BroadcastIntentActivity.java:231)
            at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:759)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5045)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
            at dalvik.system.NativeStart.main(Native Method)
 
The MainActivity is below
 
package com.example.michealsadleir.emdksamplebase;
 
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
 
import com.symbol.emdk.EMDKManager;
import com.symbol.emdk.EMDKManager.EMDKListener;
import com.symbol.emdk.EMDKResults;
import com.symbol.emdk.EMDKResults.STATUS_CODE;
import com.symbol.emdk.ProfileManager;
 
import java.util.ArrayList;
 
public class MainActivity extends Activity implements EMDKListener {
 
   //Assign the profile name used in EMDKConfig.xml   private String profileName = "DataCaptureProfile";
 
   //Assign the profile name used in EMDKConfig.xml for MSR handling   private String profileNameMSR = "DataCaptureProfileMSR";
 
   //Assign the profile name used in EMDKConfig.xml for Broadcast Intent handling   private String profileNameBroadcastIntent = "DataCaptureProfileBroadcastIntent";
 
   //Declare a variable to store ProfileManager object   private ProfileManager mProfileManager = null;
 
   //Declare a variable to store EMDKManager object   private EMDKManager emdkManager = null;
 
   //Declare a variable to store the textViewBarcode   private TextView textViewBarcode = null;
 
   //Declare a variable to store the buttonMSR   private Button buttonMSR = null;
 
   //Declare a variable to store the buttonBroadcastIntent   private Button buttonBroadcastIntent = null;
 
   //App context   static Context appContext;
 
   @Override   protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
   appContext = getApplicationContext();
 
   //The EMDKManager object will be created and returned in the callback.   EMDKResults results = EMDKManager.getEMDKManager(getApplicationContext(), this);
 
   //Check the return status of getEMDKManager   if(results.statusCode == STATUS_CODE.FAILURE)
  {
   //Failed to create EMDKManager object   }
 
 
   //In case we have been launched by the DataWedge intent plug-in   Intent i = getIntent();
  handleDecodeData(i);
  }
 
 
   //OnClickListener for buttonBroadcastIntent   private OnClickListener buttonBroadcastIntentOnClick = new OnClickListener() {
   public void onClick(View v) {
   //Launch OrderDetailActivity   Intent myIntent = new Intent(MainActivity.this, BroadcastIntentActivity.class);
  startActivity(myIntent);
  }
  };
 
   //We need to handle any incoming intents, so let override the onNewIntent method   @Override   public void onNewIntent(Intent i) {
  handleDecodeData(i);
  }
 
   @Override   protected void onDestroy() {
   // TODO Auto-generated method stub   super.onDestroy();
 
   //Clean up the objects created by EMDK manager   emdkManager.release();
  }
 
   @Override   public void onClosed() {
   // TODO Auto-generated method stub   }
 
   @Override   public void onOpened(EMDKManager emdkManager) {
   // TODO Auto-generated method stub   //EMDK opened.   this.emdkManager = emdkManager;
 
   //Get the ProfileManager object to process the profiles   mProfileManager = (ProfileManager) emdkManager.getInstance(EMDKManager.FEATURE_TYPE.PROFILE);
 
   if(mProfileManager != null)
  {
  String[] modifyData = new String[1];
 
   //Call processPrfoile with profile name and SET flag to create the profile. The modifyData can be null.   EMDKResults results = mProfileManager.processProfile(profileName, ProfileManager.PROFILE_FLAG.SET, modifyData);
 
   if(results.statusCode == STATUS_CODE.FAILURE)
  {
   //Failed to set profile   }
 
   //Call processPrfoile for profile MSR   results = mProfileManager.processProfile(profileNameMSR, ProfileManager.PROFILE_FLAG.SET, modifyData);
 
   if(results.statusCode == STATUS_CODE.FAILURE)
  {
   //Failed to set profile MSR   }
 
   //Call processPrfoile for profile Broadcast Intent.   results = mProfileManager.processProfile(profileNameBroadcastIntent, ProfileManager.PROFILE_FLAG.SET, modifyData);
 
   if(results.statusCode == STATUS_CODE.FAILURE)
  {
   //Failed to set profile   }
  }
 
  }
 
   //This function is responsible for getting the data from the intent   private void handleDecodeData(Intent i)
  {
   //Check the intent action is for us   if (i.getAction().contentEquals("com.symbol.emdksample.RECVR") ) {
   //Get the source of the data   String source = i.getStringExtra("com.motorolasolutions.emdk.datawedge.source");
 
   //Check if the data has come from the barcode scanner   if(source.equalsIgnoreCase("scanner"))
  {
   //Get the data from the intent   String data = i.getStringExtra("com.motorolasolutions.emdk.datawedge.data_string");
 
   //Check that we have received data   if(data != null && data.length() > 0)
  {
 
   //Send the order number to async to be parsed   AsyncTask task = new DownloadDataJson(this).execute(data, null, null);
  Log.d("Main order ", "Barcocde scanned :" + data.toString());
  }
  }
  }
  }
}

Please register or login to post a reply

2 Replies

V Vedsatx Saddvv

Hello Micheal, sorry for the delaIy. I'm having a trouble following the chain of events that cause this issue. It seems in the code you provide that a button click launches the BroadcastIntentActivity. Are you saying that BroadcastIntentActivity also gets launched from  the DownloadDataJason asynctask?

M Micheal Sadleir

Hi Bill,

No problem, yes the BroadcastIntentActivity gets launched when the AsyncTask completes.

CONTACT
Can’t find what you’re looking for?