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

  • SEARCH
  • Home
  • 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 7169365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:58:28+00:00 2026-05-28T14:58:28+00:00

I have a custom component which extends LinearLayout, I need to execute certain statements

  • 0

I have a custom component which extends LinearLayout, I need to execute certain statements when Layout is destroyed or removed. (or about to be removed)

One way is to check for onPause() or onDestroy() of an activity and call methods of the custom component. But I want to remove that overhead from the activity.
So that custom component itself can handle when layout is detached. But I dint find the suitable method to override (to detect the event) when layout is removed. Is there a way to handle this, or we need to use onPause() and onResume() method of activity ?

  • 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-05-28T14:58:29+00:00Added an answer on May 28, 2026 at 2:58 pm

    It is dangerous to rely on the “destruction” of a layout to execute statements, as you’re not directly in control of when that happens. The accepted way and good practice is to use the activity’s lifecycle for that.

    But if you really want to tie your component to that lifecycle, I suggest your component implements an interface (something like Removable), and do something like that in your base activity classe (that all your activities extend):

    protected Set<Removable> myRemovableItems = new HashSet<Removable>();
    
    @Override
    public void onPause() {
        super.onPause();
        for (Removable removable : myRemovableItems) {
            removable.remove();
        }
    }
    

    The interface:

    public interface Removable {
        void remove();
    }
    

    Then each time you add one of your custom component from an activity, you add the component to the internal set of Removable of the activity, and its remove method will be automatically called each time the activity is paused.

    That would allow you to specify what to do when onPause is called within the component itself. But it wouldn’t ensure it’s automatically called, for that you’ll have to do it in the activity.

    Note: you can use onStop instead of onPause depending on when you want the removal to occur.

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

Sidebar

Related Questions

I have several custom components which extends LinearLayout . Now I want to save/restore
I have a custom Swing component called NavigationLink which extends JLabel and implements a
I have a custom component which consists of 2 text view and 4 toggle
So I have a module in flex in which I add a custom component.
I have jsf application in which I have to use a facelet custom component
i have a custom component (AS3 component) which i include in my main.mxml. The
I have a custom component which contains many promptingTextInput controls. When i click a
I have two custom QML elements for audio, one for playing music (and extends
I have a custom component called shopView which is an MXML skinnable component. I
I have created a custom pipeline component which transforms a complex excel spreadsheet to

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.