Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Once solution that i would propose is this</p> <p>Create a class called callAlertBox.java like this</p> <pre><code>public class callAlertBox { private static Activity activity ; public static Activity getActivity() { return activity; } public static void setActivity(Activity mactivity) { activity = mactivity; } public static void showMyAlertBox(){ AlertDialog ad = new AlertDialog.Builder(activity).create(); ad.setCancelable(true); // This blocks the 'BACK' button if false ad.setMessage("Hello World"); ad.show(); } } </code></pre> <p>And now in every activity that might call this alert box place this code on its onResume() method</p> <pre><code>@Override protected void onResume() { super.onResume(); callAlertBox.setActivity(Act1.this); } @Override protected void onResume() { super.onResume(); callAlertBox.setActivity(Act2.this); } </code></pre> <p>Now you can call </p> <pre><code>callAlertBox.showMyAlertBox(); </code></pre> <p>from any activity and you will get the alert box</p> <p><em><strong>EDIT</em></strong></p> <p>The MainActivity.java file</p> <pre><code>public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn1 = (Button) findViewById(R.id.button1); btn1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent( MainActivity.this,Act1.class)); } }); Button btn2 = (Button) findViewById(R.id.button2); btn2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent( MainActivity.this,Act2.class)); } }); Button btn3 = (Button) findViewById(R.id.button3); btn3.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent( MainActivity.this,Act3.class)); } }); new CountDownTimer(365 * 24 * 60 * 60, 5000) { public void onTick(long millisUntilFinished) { callAlertBox.showMyAlertBox(); } public void onFinish() { //Done } }.start(); } @Override protected void onResume() { super.onResume(); callAlertBox.setActivity(MainActivity.this); } } </code></pre> <p>Now you can see from here my Countdown timer will call the method in the background casuing the dialog to appear independent of which ever activity you are in, In my case it was the main Activity and in you case there might be some updating method that is frequently called right ?? Just use that class to call the method</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload