title: How to make condition in android?
body: <p>I have a Broadcast receiver in my app and get a url from server response from server response url I split package name and save in shared preference,now scenario is that when any app is added in device it will check that app package name from my saved package name if match then pass intent. problem is that when variable which I declared earlier was empty then how to match new package added with my saved packge.shows me null pointer exception.</p>
  
  <p>here is code:-</p>
  
  <pre><code>public class CAppDownloadReceiver extends BroadcastReceiver {
  String url, packageName, s_szDealCode;
  CDealBuySharedPreference m_oSharedPreference;
  
  /**
   * Get Query String as Key-Value Pair.
   */
  public static Map&lt;String, String&gt; getQueryMap(String query) {
      Map&lt;String, String&gt; map = new HashMap&lt;&gt;();
      String[] queryString = query.split("\\?");
      if (queryString.length &gt; 1) {
          String[] params = queryString[1].split("&amp;");
          for (String param : params) {
              String name = param.split("=")[0];
              String value = param.split("=")[1];
              map.put(name, value);
          }
      }
      return map;
  }
  
  @Override
  public void onReceive(Context context, Intent intent) {
      m_oSharedPreference = new CDealBuySharedPreference(context);
      HashMap&lt;String, String&gt; user = m_oSharedPreference.getDealUrlDetails();
      try {
          if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) {
              String installAppPackgeName = intent.getData().getSchemeSpecificPart();
              url = user.get(CDealBuySharedPreference.s_szDealUrl);// getting mobile from saved preferences..........
              packageName = getQueryMap(url).get("id");
              System.out.println("Previous package stored :" + packageName);
              System.out.println("new Package added" + installAppPackgeName);
              if (installAppPackgeName.equals(packageName)) {
                  // If install app package name is same as url package name then do some task.
                  // Your app is installed now.
                  s_szDealCode = user.get(CDealBuySharedPreference.s_szDealCode);
  
                  System.out.println("Match...");
                  System.out.println("Broadcast url..." + url);
                  System.out.println("Broadcast deal code:-" + s_szDealCode);
  
              } else {
                  System.out.println("does not match ");
              }
          }
  
  
      } catch (Exception e) {
          e.printStackTrace();
      }
  
  }
  </code></pre>
  
  <p>}</p>