title: Android: how to use ContentResolver in background
body: <p>I have class that extends <code>BroadcastReceiver</code> and gets all new sms. </p>
  
  <p>When I get new sms I want to search the phonebook to check if phone numbers inside this message are in phone book, and if they are, send sms with result to another phone.</p>
  
  <p>I use <code>ContentResolver</code> to check the phone numbers, but to use it I need to use it inside Activity or have pointer to activity, but my sms listener works in background. </p>
  
  <p>Is there a way to search phone book without activity or to get valid activity from context or intent that I get when recieving new sms?</p>
  
  <p>I tried to use something like that:</p>
  
  <pre><code>                    Activity act = new Activity();
                      DBManager dbm = new DBManager(act);
                      ArrayList&lt;MyContact&gt; res = dbm.phoneSearch(sms_ar[1]);
                      SmsSender sms = new SmsSender(act);
                      if(res.size() &gt; 0){                     
                          String answer = res.get(0).getName()+CSStatic.SMS_SEPARATOR+res.get(0).getPhone();
                          for(int z = 1; z &lt; res.size(); z++){
                              answer = answer+CSStatic.SMS_SEPARATOR+res.get(z).getName()+CSStatic.SMS_SEPARATOR+res.get(z).getPhone();
                          }
                          Log.d("sms", "Answer: "+answer);
                          sms.smsAnswer(answer, sms_ar[2]);
                      } else {
                          String phone = dbm.getPhoneToQuery(sms_txt);
                          sms.smsQueryNext(sms_txt, phone);
                      }
                      act.finish();
  </code></pre>
  
  <p>but it don't work :P
  In DBManager I search for phones and in SmsSender I send new sms.</p>