SQL Server & android sqliteの間でレプリケーションを行いたい。うまくいきました。Androidサービス - サービスを開始して別のアクティビティにリダイレクト
請求書/ユーザーが[戻る](私のアプリケーションの戻るボタン)ボタンをクリックすると、前/次のアクティビティに進む必要があります&もサービスを開始する必要があります。私は次の活動に行くのを待っていません。
問題は次のとおりです。サービスを使用してこれを実行しました。それもいいです。しかし、ユーザーが戻るボタンをクリックすると、サービスが終了するまで待っています。その後、それは前/次の活動に行くだけです。
これが私の背中のボタンのコードです:
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();
}
}
});
これは私のサービスコードです:
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<String> uploadFiler = new ArrayList<String>();
HashMap<Integer,String> uploadTable = new HashMap<Integer, String>();
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() > 0){
for (Map.Entry<Integer, String> 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;
}
Problem is don't need to wait until finish service, it need to go next activity
この質問から私を助けてください。
なぜ新しいスレッドでサービスを開始しないのですか? –