警报框不可见

发布于 2025-01-01 06:49:31 字数 721 浏览 3 评论 0原文

我正在进行一项检查位置更改的活动,如果大约 1 分钟没有位置更改,它会显示一个警报框。我面临的问题是,如果我正在处理另一项活动,则第一个活动的警报框对我来说是不可见的。仅当我返回到之前的活动时,我才能看到警报框。有什么方法可以显示后台活动的警报框以显示在其他活动活动之上。请帮助我找到解决方案。

这是我用来显示警报框的方法

public void alerter(String msg)
    {
      AlertDialog.Builder builder = new AlertDialog.Builder(Location_Tracker_Individual_Service_Providers.this);
      builder.setMessage(msg)
             .setTitle("Warning!")
                         .setNegativeButton("OK", new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int id) {
                      dialog.cancel();
                 }
             });

    AlertDialog alert = builder.create();
    alert.show();
    }

I am having an activity which checks for location changes and it shows an alert box if there is no location change for about 1 minitue. The problem that i am facing is that, if i am working on another activity the alert box of first activity is not visible to me. I can only see the alert box if I go back to previous activity. Is there any way to display an alert box from an activity in back ground to appear over other active activities. Kindly help me to find a solution.

This is the method that i am using to display alert box

public void alerter(String msg)
    {
      AlertDialog.Builder builder = new AlertDialog.Builder(Location_Tracker_Individual_Service_Providers.this);
      builder.setMessage(msg)
             .setTitle("Warning!")
                         .setNegativeButton("OK", new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int id) {
                      dialog.cancel();
                 }
             });

    AlertDialog alert = builder.create();
    alert.show();
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

靑春怀旧 2025-01-08 06:49:31

也许创建另一个类,其中包含一组警报函数(该类以某种方式或在父活动中是全局的)。从子活动中调用此类中的函数应该允许您在需要时显示它们。另一种选择是在两个活动中创建警报并将它们链接起来,以便当调用第一个活动时它会调用第二个活动。

Perhaps create another class, with the set of alert functions(this class being global in a manner or in the parent activity). Calling the functions in this class from child activities should allow you to display them whenever required. Another option would be to create the alert in both activities and linking them, so that when the first is called it calls the second.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文