title: Android Service- Start service & redirect to another Activity
body: <p>I want to do replication between sql server &amp; android sqlite.That is working fine. </p>
  
  <p>Once I put invoice/User click Back (my application back button) button, it need to go previous/next activity &amp; have to start service also. I don't want to wait to go next activity.</p>
  
  <p>Now the problem is : I have done this using Service. That is also fine.But when the user click back button, it wait until the service finish. after that only it go to previous/next activity.</p>
  
  <p>This is my back button code:</p>
  
  <pre><code> Button reOpCancel = (Button)findViewById(R.id.reOpCancel);
      reOpCancel.setOnClickListener(new OnClickListener() {
             public void onClick(View v) {
  
                  Intent i = new Intent(getBaseContext(), ListRetailerActivity.class);
                  Bundle bundle = new Bundle();
                  bundle.putString("RetailerName", retailerName);
                  bundle.putString("RetailerCode", relailerCode);
                  bundle.putString("RouteCode", routeCode);
                  i.putExtras(bundle);
                  View vi = SalesActivityGroup.group.getLocalActivityManager().startActivity("ListRetailerActivity", i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
                  SalesActivityGroup.group.replaceView(vi);
  
                 ConnectivityManager manager = (ConnectivityManager) getSystemService(LoginActivity.CONNECTIVITY_SERVICE);
                  boolean is3g = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
                  boolean isWifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
                  if(is3g ||isWifi){
                      startService(new Intent(RetailerOptionActivity.this, UploadService.class));
                  }else {
                      Toast.makeText(SalesActivityGroup.group.getParent(), "GPRS/WIFI is not available", Toast.LENGTH_LONG).show();
                  }
             }
      });
  </code></pre>
  
  <p>This is my service code:</p>
  
  <pre><code> public class UploadService extends Service {
  private static final String TAG = "UploadService";
  private  String APPURL = "";
  private  String NAMESPACE = "http://tempuri.org/";
  private  String METHOD_NAME = "convertJSONToDataSet";
  private  String SOAP_ACTION = "http://tempuri.org/IXontService/convertJSONToDataSet";
  ArrayList&lt;String&gt; uploadFiler = new ArrayList&lt;String&gt;();    
  HashMap&lt;Integer,String&gt; uploadTable = new HashMap&lt;Integer, String&gt;();
  private String strBusinessUnit= "";
  private String strExecutive = "";
  private ConnectivityManager manager;
  private Boolean is3g = false;
  private Boolean isWifi = false;
  private int networkType;
  
  
  @Override
  public IBinder onBind(Intent arg0) {
      return null;
  }
  
  @Override
  public void onCreate() {
      Toast.makeText(this, "Upload Service Created", Toast.LENGTH_LONG).show();
      Log.d(TAG, "onCreate");
      SharedPreferences myPrefs = this.getSharedPreferences("myLogedPrefs",MODE_PRIVATE);
      strBusinessUnit = myPrefs.getString("BusinessUnit", "");
      strExecutive = myPrefs.getString("Executive", "");
  
      manager = (ConnectivityManager) getSystemService(DownlaodTableActivity.CONNECTIVITY_SERVICE);
      is3g = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected();
      isWifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
  if (is3g) {
          APPURL =  getServicePath("G");;
      }else if (isWifi) {
          APPURL =  getServicePath("L");;
      }else if(networkType == TelephonyManager.NETWORK_TYPE_GPRS) {
          APPURL =  getServicePath("G");;
      }
  
  }
  @Override
  public void onDestroy() {
      Toast.makeText(this, "Upload Service Stopped", Toast.LENGTH_LONG).show();
      Log.d(TAG, "onDestroy");
  }
  
  @Override
  public void onStart(Intent intent, int startid) {
  
      Toast.makeText(this, "Upload Service Started", Toast.LENGTH_LONG).show();
  
      if(! APPURL.equals("")){
          boolean result = uploadUsingService();
          if(!result) {
              Toast.makeText(this,"Service is not working  OR Time out to Connect to service !!!!!!!",Toast.LENGTH_LONG).show();
          }
      }else{
          Toast.makeText(this, "GPRS/WIFI is not available", Toast.LENGTH_LONG).show();
      }
  
      Log.d(TAG, "onStart");
      onDestroy();
  
  }
  
      uploadTable = getUploadTable();
  
      boolean result = true;
  
      DBAdapter dbAdapter = DBAdapter.getDBAdapterInstance(this);
      dbAdapter.openDataBase();
      System.out.println("==APPURL="+APPURL);
  
  
          try {
              if(uploadTable.size() &gt; 0){
                  for (Map.Entry&lt;Integer, String&gt; entry : uploadTable.entrySet()) {
                      String value = entry.getValue();
                      if(value.equals("WMInvoiceHeader")){
                          result = getInvoiceHeader();
                      }else if(value.equals("WMInvoiceLine")){
                          result = getInvoiceLine();
                      }else if(value.equals("WMInvoiceHeaderDiscount")){
                          result = getInvoiceHeaderDiscount();
                      }else if(value.equals("WMInvoiceSpecialDiscount")){
                          result = getInvoiceSpecialDiscount();
                      }else if(value.equals("WMInvoiceCancelHeader")){
                          result = getInvoiceCancelHeader();
                      }else if(value.equals("WMInvoiceCancelLine")){
                          result = getInvoiceCancelLine();
                      }else if(value.equals("WMTransactionControl")){
                          result = getTransactionControl();
                      }else if(value.equals("WMVisitDetail")){
                          result = getVisitDetail();
                      }else if(value.equals("WMVisitHeader")){
                          result = getVisitHeader();
                      }else if(value.equals("WMReturnHeader")){
                          result = getReturnHeader();
                      }else if(value.equals("WMReturnLine")){
                          result = getReturnLine();
                      }else if(value.equals("WMPaymentReceipt")){
                          result = getPaymentReceipt();
                      }else if(value.equals("WMPaymentAllocation")){
                          result = getPaymentAllocation();
                      }
                      System.out.println("==result=="+result);
                      if(!result) break;
                  }
  
  
          }
          dbAdapter.close();
          } catch (Exception e) {
              System.out.println("==ERROR=="+e.getMessage());
              e.printStackTrace();
          }
  
  
      return result;
  }
  </code></pre>
  
  <p><code>Problem is don't need to wait until finish service, it need to go next activity</code></p>
  
  <p>Please help me out from this question.</p>