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 8249995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:44:00+00:00 2026-06-07T23:44:00+00:00

My Activity holds a member member_one which holds another member member_two which can throw

  • 0

My Activity holds a member member_one which holds another member member_two which can throw an Exception. I need to show user a Toast if this Exception happens. In order to show a Toast I need to throw Exception from member_tow to member_one and then from member_one to my Activity. This approach leads to big changes and I don’t want to do so. May be I just think wrong, is there any easy way to handle the exception?

  • 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-07T23:44:01+00:00Added an answer on June 7, 2026 at 11:44 pm

    So far I know there will be two solutions of the problem.

    • pass Context to you member_one, member_two and then use that Context to make Toast. Like Toast.makeText(mContext, "Exception Occurred", Toast.LENGTH_SHORT).show();

    Second approach will be through Interface

    -Make a Interface method in your class of member_one and so on

    like

    public interface OnErrorOccured {
            public void whatIsErr(String msg);
        }
    
        OnErrorOccured onError;
    
        public void setOnDetailsLoadListener(OnErrorOccured onError) {
            this.onError = onError;
        }
    `
    

    and when ever you getException call onError.whatIsErr(e.toString());

    and in main Activity

     member_one.setOnErrorListener(mErrorOccured);
    
     OnErrorOccured mErrorOccured =new OnErrorOccured() {
    
        @Override
        public void whatIsErr(String msg) {
            // Do what ever you want..show Toast, or do any UI update
    
        }
    };
    

    How other programmers know if they want to use one of these classes they need to set listeners?

    Well for this you force the constructor to pass a listener.

    Like

    public yourConstructor(OnErrorOccured errorListener,.....)
    {
       this.setOnErrorListener(errorListener);
       ...
    
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Activity consists of GridView which holds 40+ elements. After starting activity user could
I created an activity which holds 3 custom components (defined in xml). 2 components
this is the current state/situation: I have an Activity which binds a Service which
Good day. I have an app that has one main activity which holds 3
I would like to use one Activity which holds several fragments and navigate among
I have a main activity, that holds the main menu. This menu has an
This activity is used for login. It post the username and password to a
My application has one activity which starts two services but does not bind them.
I have an activity, where the ListView holds customized linear layout elements for each
I have a main activity with this layout file: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android

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.