Code example for Intent

Methods: getParcelableExtragetStringExtra

0
    } 
  } 
   
  @Override 
  protected void onHandleIntent(Intent intent) {
    String script=intent.getStringExtra(SCRIPT);
     
    if (script!=null) {
      try { 
        success(intent, i.eval(script).toString());
      } 
      catch (Throwable e) {
        Log.e("BshService", "Error executing script", e);
         
        try { 
          failure(intent, e.getMessage());
        } 
        catch (Throwable t) {
          Log.e("BshService",
                "Error returning exception to client", 
                t);
        } 
      } 
    } 
  } 
   
  private void success(Intent intent, String result) {
    send(intent, result, SUCCESS);
  } 
   
  private void failure(Intent intent, String error) {
    send(intent, error, -1);
  } 
   
  private void send(Intent intent, String result, int code) {
    String broadcast=intent.getStringExtra(BROADCAST_ACTION);
    Intent data=new Intent();
     
    data.putExtra(PAYLOAD, result);
    data.putExtra(RESULT_CODE, code);
     
    if (broadcast==null) {
      PendingIntent pi=(PendingIntent)intent.getParcelableExtra(PENDING_RESULT);
       
      if (pi!=null) {
        try { 
          pi.send(this, Activity.RESULT_OK, data);
        } 
        catch (PendingIntent.CanceledException e) {
          // no-op -- client must be gone 
        } 
      } 
    } 
    else { 
      data.setPackage(intent.getStringExtra(BROADCAST_PACKAGE));
      data.setAction(broadcast);
 
      sendBroadcast(data);
    } 
  }