Newbie Question - How to handle "Subroutines" ?

Put your problem here if it does not fit any of the other categories.

Newbie Question - How to handle "Subroutines" ?

Postby dlauxx » Sun Feb 05, 2012 2:04 pm

I am new to Android and have some questions about how to handle I so called "Subroutines".

My is to handle user input and to display the results. I group other "subroutines" such as
some mathematical calculations like converting Gregorian Day to Julian Day, into a separate class.

I have the following questions:-

1) Should I use class "implement" "interface"?
2) Should I use class "Activity"?
3) How do I pass arguments to the called subroutine and retrieve values back to
4) Can the subroutines within the that class to call each other ?

Yes, a very basic stuff, but would appreciate it if anyone could offer some help or point me in
the right direction to find the solutions.

Posts: 4
Joined: Sun Feb 05, 2012 1:18 pm


Re: Newbie Question - How to handle "Subroutines" ?

Postby Phyll » Sun Feb 05, 2012 3:52 pm

Hi dlauxx,

Here is an example class you can use for a template.

Code: Select all
package com.bandpsoftware.app5;

import android.content.Context;

//This is the class declaration for a class that has the
//basic parts.
//This can extend other classes and implement things here.
public class MyMathStuff {   
   //Fields in the class
   private Context context = null;
   private Double PI = 3.14159;
   public MyMathStuff(Context ctx) {
      //The constructor does anything you might
      //have to do to initialize fields.
      //You might need to have the context from your activity
      //and this is one way to have it available to your methods
      //in the class
      context = ctx;
   //Setters and Getters
   //These keep your fields private and can filter input into
   //them, etc. help with the encapsulation of these
   public void setPi(Double dValue) {
       PI = dValue;
       }//pi setter
   public Double getPi() {
       return PI;
       }//pi getter
   //These do the work for the class
   public Double add(Double a, Double b) {
        return a + b;

   public Double subtract(Double a, Double b) {
      return a-b;
   //More Methods
    //To use this class-
   //Create an instance of it like this:
   //    MyMathStuff mathStuff = new MyMathStuff(App5.this);
   //Now you can reference one of the methods or fields like this:
   //    mathStuff.setPI(3.14);
   //    Double myResult = mathStuff.add(16.12341,13.2356);
   //Of course these exact names will only work with this
   //your names will vary

Hope this helps.

Master Developer
Master Developer
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Newbie Question - How to handle "Subroutines" ?

Postby jonbonazza » Sun Feb 05, 2012 6:55 pm

I suggest you work on learning the Java programming language before moving on to Android programming. Without knowing the basics of OOP and Java, you won't make it very far in Android programming.
Master Developer
Master Developer
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Re: Newbie Question - How to handle "Subroutines" ?

Postby dlauxx » Mon Mar 12, 2012 6:20 am

Thanks Phyll and jonbonazza for your help and comments.

I have solved the problem by creating a class containing all my functions. It works fine now.

Thanks again.
Posts: 4
Joined: Sun Feb 05, 2012 1:18 pm


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 13 guests