I have developed an application with both Activity and a background Service
. My main Activity A
is a Tab Host
which starts the Service S and Activity B,C and D with tabs via Intent
.
The Service S
gets data from a remote database and stores it in the application's local database.
If there is a data from the Remote database
, the Service S starts an Activity E with an Alert Box
. Once i click the OK button of the Alert Box
, the main Activity A(Tab Host) is opened.
Imagine the user is in Activity B and if the dialog box opens, after clicking OK button the user is switched to Activity A rather than Activity B. How can i go to Activity B(current active activity)?.
Part of Activity with Alert box.
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();
}}}