有没有一种方法来创建控制我的应用程序的若干活动的控股实例? [英] Is there a way to create a controlling instance that controls several activities of my app?

查看:137
本文介绍了有没有一种方法来创建控制我的应用程序的若干活动的控股实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上有几个开发商的一个项目工作。
我们在一个相当大的应用程序工作。
每个开发者有几个活动可以看作是整个主应用程序的子应用程序。

I work on a project that has several developers. We work on one rather large app. Every developer has several activities that can be seen as sub-apps of the whole main-app.

我不明白,这可能不是最好的设计,但它的存在,我们必须以某种方式处理它。

I do realize, that this may not be the best design, but it exists and we have to handle it somehow.

现在的主要问题是,我们需要一个高手,那始终是积极和检查的I / O等,并能发出状态更改为每个子应用程序/活动。像我们刚刚失去了互联网连接等。

Now the main issue is, that we need a master, that is always active and checks I/Os etc and that can give out status changes to every sub-app/activity. Something like "we just lost internet connection" etc.

现在,master是一个单,即首先由发射活动,每个活动/次的应用程序可以通过传递适当的接口取决于什么更新活动希望收到注册实例化。

Right now, that master is a singleton, that is first instantiated by the launcher activity and that every activity/sub-app can register to by passing the appropriate interfaces depending on what updates the activity would like to receive.

这是工作,但它感觉不对,因为单需要上下文来访问系统资源,以确定系统为static喜欢上网或GPS。如果单由OS杀死,不是简单的的getInstance不会做多好,因为单会以某种方式需要获得一个上下文。我读过有关扩展应用程序类和创建静态成员背景下出现的,但这个变量必须是动荡,其可能的,如果整个应用程序在某些重启,崩溃后返回null /杀状态。它不安全感。

This is working, however it doesn’t feel right, because the singleton needs context to access system resources to determine system stati like internet or gps. Should the singleton be killed by OS, than a simple "getInstance" wouldn’t do much good, because the singleton would somehow need to acquire a context. I've read about extending the Application class and creating a static member context there, but this variable had to be volatile AND its possible that it returns null if the entire app is in some restart-after-crash/kill state. It doesn’t feel safe.

在另外,也应该是主某种方式打开一个用户对话,以显示警告等给用户的可能性。这些警告应该是相同的整个应用程序,并没有开发应该担心的时候为什么突然弹出。眼下,这些消息显示为覆盖所有定制的祝酒词。当然,他们需要上下文,如果应用程序即将关闭有可能是一个问题。

In addition, there should also be a possibility that the master somehow opens a user-dialog to display warnings etc to the user. Those warnings should look the same across the entire app and no dev should have to worry about when or why it suddenly pops up. Right now, those messages appear as custom toasts that overlay everything. Of course they require context and if the app is about to close there could be a problem.

所有的一切,那是一塌糊涂,我们是在和我正在寻找一个解决方案。

All in all, that’s the mess we are in and I’m looking for a solution.

那么,如何创造一个安全的主对象或活动(甚至是服务?!),可以通过不同的活动和后警告等(甚至有收活动,或至少令他们关闭自己的能力信息而不需要以注册can_close接口)。

So how do I create a safe master object or activity (or even service ?!) that can pass info to different activities and post warnings etc (and Maybe even has the ability to close activities or at least order them to close themselves without the need to register a can_close interface).

这应该是安全的,如果之后崩溃的Andr​​oid只是重启,这是积极的它在某种程度上设法也重新启动,或者至少有活动/像以前一样提供相同的信息。

It should be that safe, that if after a crash android only restarts the activity that was active it somehow manages to also be restarted or at least have/give the same info as before.

每一个想法是值得欢迎的,但应用程序的总检修是不可能的(缺乏时间和人力)

Every idea is welcome but total overhauls of the app are just not possible (lack of time and manpower)

推荐答案

下面是一些建议:


  1. 为创建一个服务组件中的所有监控你需要做的。
    如果我理解正确的话,这项服务将被要求只有当
    一些活动正在运行。所以,你可以把它约束
    服务。让我们到时,他们启动此服务的所有活动绑定
    并解除绑定,当他们关闭。该服务将启动时的
    第一项活动结合。

  2. 创建您的所有活动的基类。你可以在这里写的所有普通code。例如在code结合并交换信息
    与主服务。这个类也可以包含实用方法
    通知用户等,因此,所有的活动都将使用相同​​的方法
    通知。

  3. 对于用户通知,您既可以使用状态栏通知或创建一个片段可同时采集,汇总
    并显示通知。你可以有一个共同的菜单项
    在基Activity类实现显示/隐藏此片段。
    如果使用状态栏通知,请确保您使用一个汇总
    通知您的应用程序。否则,不同的活动可能
    创建在状态栏杂波。

  1. Create a Service component for all the monitoring you need to do. If I understand correctly, this service will be required only if some of the activities are running. So you can make it a bound service. Let all activities bind to this service when they start and unbind when they close. The service will be started when the first activity binds.
  2. Create a base class for all your activities. You can write all the common code here. e.g. the code to bind to and exchange messages with the master service. This class can also contain utility methods for notifying user etc. So all activities will use the same method for notification.
  3. For user notifications, you could either use Status Bar Notification or create a Fragment which can capture, aggregate and display the notifications. You can have a common menu item implemented in the base Activity class to show/hide this Fragment. If you use Status Bar Notification, make sure you use one aggregated notification for your app. Otherwise, the different activities might create a clutter in the status bar.

这篇关于有没有一种方法来创建控制我的应用程序的若干活动的控股实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆