2012-09-17 50 views
0

我開發了一個具有活動和背景Service的應用程序。我的主要Activity ATab Host,它開始Service S and Activity B,C and D with tabs via Intent在Android中單擊對話框的確定​​按鈕後,轉到當前活動活動

服務S從遠程數據庫獲取數據並將其存儲在應用程序的本地數據庫中。

如果有一個數據來自Remote databaseService S starts an Activity E with an Alert Box。一旦我點擊OK button of the Alert Box,主要活動A(Tab主機)就會打開。

想象一下,用戶在活動B中,如果對話框打開,點擊確定按鈕後,用戶切換到活動A而不是活動B.我怎樣才能去活動B(當前活動活動)?

帶警示框的活動的一部分。

public class Popup extends Activity{ 
int value = 0; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.dialog); 

    Bundle extras = getIntent().getExtras(); 
    if(extras !=null) 
    { 
     value = extras.getInt("key") ;  
    } 

    AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    if(value == 1){ 
     builder.setMessage(value + "new task has been assigned").setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() { 


      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       // TODO Auto-generated method stub 
       //mp.stop(); 

       Popup.this.finish(); 

      } 
     }).show(); 
    } 

    else { 
     builder.setMessage(value + " " + "new tasks has been assigned").setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() { 


      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       // TODO Auto-generated method stub 
       //mp.stop(); 

      } 
     }).show(); 
    }}} 

回答

0

你只需要改變的代碼對你onClick EventAlertBox保持Blankl留在同一個活動

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    if(value == 1){ 
     builder.setMessage(value + "new task has been assigned").setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 


     } 
    }).show(); 
} 

else { 
    builder.setMessage(value + " " + "new tasks has been assigned").setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() { 


     @Override 
     public void onClick(DialogInterface dialog, int which) { 

     } 
    }).show(); 
0

在活動A(TabHost),使用TabHost getCurrentTab確定當前選項卡的方法,並使用setCurrentTab來設置當前選項卡。

0

你當前活動將在在onPause()狀態時,警告框來,所以需要ovveride的onPause()方法和一些布爾varible設置爲true,然後做你進一步的東西在的onResume()方法,這樣

private boolean state=false; 
    onPause(){ 
    state=true; 
super.onPause(); 
} 
onResume(){ 
    if(state==true){ 
//do your required stuff,for example you want to stay in current activity(B) 
     A.tabHost.setCurrentTab(here set B activity tab index);//declare tabHost variable as public static in activity A. 
super.onResume(); 

}

}

相關問題