Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7995671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:29:19+00:00 2026-06-04T14:29:19+00:00

Coming from a non-Java background, I find myself writing a lot of View classes

  • 0

Coming from a non-Java background, I find myself writing a lot of View classes with extensive functionality (in an effort to be portable), that don’t necessarily fit nicely into the Android FW setup as far as maintenance – for example, I might have a widget that does something on a interval that I want to stop and clean up when an Activity is paused/stopped/destroyed. Generally I can manage this by just calling a public method on the widget from the containing Activity, but A) sometimes this gets pretty deep, and having to create a public method to access a child in every parent can get ugly, and B) requires extra (uneeded?) attention.

I’m considering using an approach like a global delegate to manage this kind of thing, but have read a lot of warnings about this sort of approach – would something like the class that follows have any inherent flaws that I might be missing?

import java.util.HashMap;
import java.util.HashSet;

public class ActiveRegistry {

    private static final ActiveRegistry instance = new ActiveRegistry();
    public static ActiveRegistry getInstance(){
        return instance;
    }

    private HashMap<String, HashSet<Runnable>> registry = new HashMap<String, HashSet<Runnable>>();
    private ActiveRegistry(){

    }

    public void register(String key, Runnable runnable){
        if(!registry.containsKey(key)){
            HashSet<Runnable> list = new HashSet<Runnable>();
            registry.put(key, list);
        }
        HashSet<Runnable> list = registry.get(key);
        list.add(runnable);
    }

    public void execute(String key){
        if(registry.containsKey(key)){
            HashSet<Runnable> list = registry.get(key);
            for(Runnable runnable : list){
                runnable.run();
            }
        }
    }
}

Use might be something like…

  1. A View has something that needs to be cleaned up. On instantiation, register it… ActiveRegistry.getInstance().register("paused", someRunnableThatCleansUpStuff)
  2. Extend Activity so that onPause calls ActiveRegistry.getInstance().execute("paused");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:29:21+00:00Added an answer on June 4, 2026 at 2:29 pm

    You are doing way more work than you need to. Using Fragments (from the support package, if you want to ensure backwards compatibility with older versions of android), will make your life a whole lot easier. Each fragment is embedded in an activity and has a lifecycle that is directly linked with its host activity’s lifecycle. Using them should significantly reduce the complexity of your code, as most of what you are currently worrying about will be managed by the system instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Coming from a non-Java background to Scala has brought me a wide range of
Coming from a PHP background, I'm used to writing small functions that return a
Coming from a non-OO background in Matlab, I'm looking to perform some of the
My supervison, coming from a non-.net background wants me to use his special version
Coming from a Java background, I'm quite fond of static type safety and wonder
This question may seem rather basic, but coming from an engineering (non computer-science) background,
coming from node.js point of view, where all code is non-blocking. In Go, non-blocking
Coming from a non-SQL background, I've been having a hard time absorbing SQLite3 for
Sorry for a badly-phrased question. I have a requirement coming from a non-technical person
Coming from a .NET background I'm use to reusing string variables for storage, so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.