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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:59:36+00:00 2026-06-15T03:59:36+00:00

My app contains two classes: MainActivity, Activity2. Activity2 needs to access a non-static method

  • 0

My app contains two classes: MainActivity, Activity2.
Activity2 needs to access a non-static method of MainActivity. How to do that?

I’m new with Java and Android, if you can, please explain clearly for beginners what to do.
Thanking you in advance.

  • 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-15T03:59:38+00:00Added an answer on June 15, 2026 at 3:59 am

    Instead of calling methods from a different activity you should use Bundles to pass values from ActivityA to ActivityB when B is started from A.

    Alternatively if you want to reuse code you should create a non-activity object which you can create two instances of. Say if you do a lot of heavy calculations in both activities, you can put your calculating code in a “Calculate” object. And just initiate it like you would any other Java object. Just note that these two instance will not share any data between each other.

    Calculate calc = new Calculate();
    calc.codeIdLikeToReuse(numbersAndStuff);
    

    Hope this helps. I would recommend that you read up on the Activity Life Cycle to get an idea on how the life on an activity is.

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

Sidebar

Related Questions

I have an app that contains two buttons, both that are suppose to take
I’m working on the web app where the main page contains two parts: the
I have an app that contains several activities...so lets say user is navigating activity
I've created an app that contains 4 viewcontroller and its .h,.m files...In my firstviewcontroller
I've created an app which contains form and that have to filled up in
I've built an ASP.NET application and noticed that my /App_Data folder contains two files:
I've an EAR app contains two modules. EJB Module and Web Module. In web
I am devloping a web app using Drupal. My form contains two buttons, Submit
I have an interface and two classes that implements it. One of them has
Can I create a universal binary for Mac OS X that contains two versions

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.