我开发了一个包含Activity和后台Service
的应用程序。我的主要Activity A
是Tab Host
,它启动Service S and Activity B,C and D with tabs via Intent
。
服务S
从远程数据库获取数据并将其存储在应用程序的本地数据库中。
如果来自Remote database
,Service S starts an Activity E with an Alert Box
的数据。单击OK button of the Alert Box
后,将打开主活动A(选项卡主机)。
想象一下,用户在活动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 :(得分:0)
您只需更改onClick Event
AlertBox
中的代码,并将其保留为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();
答案 1 :(得分:0)
在活动A(TabHost)中,使用TabHost getCurrentTab
方法确定当前标签,并使用setCurrentTab
设置当前标签。
答案 2 :(得分:0)
当警报框出现时,你当前的活动将处于onPause()状态,所以需要ovveride onPause()方法并将一些布尔变量设置为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();
}
}