Android : Change Variables From Different Classes?

Jun 6, 2010

Before I delve into it, I'm very new to Android and I have just started learning Java last month. I've hit bumps while trying to develop my first simple app. Most of these hurdles were jumped thanks to random tutorials online. MY CODE IS VERY MESSY. Any tips are appreciated.

The question above is quite broad, but this is what I want to do: It's a essentially a blood alcohol content calculator / drink keeper-tracker. Basic layout: http://i.imgur.com/JGuh7.jpg

The buttons along the bottom are just regular buttons, not ImageButtons (had problems with that) Here's some example code ..

It outputs the following to the text view: "Your BAC is -0.017". This is the Bac value for if StandardDrinks was still 0, so obviously there is some problem communicating between the classes.

The other elements of the formula (weight, time spent drinking, and the alcohol %'s and such) are variables because I will ultimately allow the user to change those values in the settings.

I've heard around the water cooler that global variables are not good programming style, but this is the closest I've come to getting it to work..

Android : Change variables from different classes?


Android :: Why I Can't Access Protected Member Variables In Droid Classes?

Jun 18, 2009

When I extend a View, I cannot access the protected member variables from my code. Eclipse just says that there exists no variable with that name (for instance mScrollX). Why is that?

View 2 Replies View Related

Android :: Service Change Values Of Variables And UI Textfields Of Activities

Oct 20, 2010

I have an application that get/send data from/to a remote DB on internet.

I need to get my application working in background mode, then i supose that i have to put all the send/get remote data in a service..... but.... How can this service change values of variables and UI textfields of my activities? i can't find any information about this, all the tutorials i am finding are of simple services that doesn't do something like that.

View 7 Replies View Related

Android :: Change Textview Text From String Array In Widget Without Global Variables

Nov 21, 2010

I am trying to make an android widget like the Google Voice Widget where users can go through an array of Strings which is retreived from the SQLite database. The problem is using global variables in the widget provider. I need to hold the index of the value they are currently on in order to pass it to the intents which are created when the left or right buttons are created. The variable is always returned as zero though.

CODE:..................

View 1 Replies View Related

Android :: How To Make Variables Global?

Mar 28, 2009

Can anyone hep me with how to make a (boolean) variable global in Android?

View 2 Replies View Related

Android :: Pass Variables To An Outside Class?

Aug 12, 2010

I split my inner View class from my Main class into its own file. In my main class, I have the view set as an onTouchListener which records user movement into a matrix so it can translate and scale the view. After separating it everything works but im unsure how to pass the matrix to the View for onDraw to update. Any suggestions?

View 1 Replies View Related

Android :: Need To Use Static Variables In Droid

Mar 19, 2010

In android, are using static variables a recommended practice?
E.g, implementing a Singleton pattern in Java, I usually do...

Also, when does this get cleaned up by the Android JVM?

View 6 Replies View Related

Android :: Activity Lifecycle And Static Variables

Jul 14, 2009

I just ran into a situation where it looks like a static variable reference is persisted across activity sessions. I didn't expect that because I thought that when an activity exits, it's de-referenced and garbage collected. I am wondering if anyone can shed some (more) light on when the VM eliminates object references for Activities and Services and in particular when static variables get reset to default values?

View 7 Replies View Related

Android :: Make Variables And Multiple Activities?

Oct 12, 2010

How can I make a variable or object available to multiple activities or restarts of the same one.

View 1 Replies View Related

Android :: Alternatives To Static Variables In Droid?

Jun 17, 2010

I am using static Arrays and HashMaps to store some values in my AppWidgetProvider class. But they are becoming null when the process dies, so the widget does not work anymore. Are there any alternatives to using static members to store data for an AppWidgetProvider in Android?

View 5 Replies View Related

Android :: Get Variables / Data From One Screen To Another In Phone?

Feb 27, 2010

In android: I'm trying to take data from one activity/screen to another.

Let's say I'm adding two numbers. I layout my first screen (xml) with 2 EditText views, a couple labels, and an 'OK' button. Now, I want to add the numbers that I've input into the EditText views. Let's say I input 2 and 2 (2 + 2 = 4).

Now, when I hit the 'OK' button, I want a new screen/activity to appear and simply show me the answer (4). Do I use global vars to do this?

View 3 Replies View Related

Android :: Threads Cache Instance Variables?

Jul 3, 2010

I am starting to develop an Android App and have noticed the following behaviour in my test code (not yet designed the real app):

A thread that loops around doing Bluetooth IO accesses an instance variable that is declared in the enclosing class. That instance variable gets set to null by the GUI thread in the onBackPressed() method which also closes the Bluetooth socket which causes an exception in the IO thread (which is what I want).

The odd thing is that if I set the instance variable to null before I close the socket, the IO thread sees the null value, but if I close the socket first and then set the variable to null, the IO thread doesn't see the null value.

The instance variable is being used in a loop in the IO thread and it appears as if that variable is being cached while within the loop. So any changes to that variable by another thread are not visible. Is that possible? If so, is there a workaround to guarantee that the VM will read the value of the instance variable?

View 4 Replies View Related

Android :: Get User Defined Environment Variables?

Sep 20, 2010

I would like to use self defined Environment variables in my source code.

I use System.getenv() to do this and the code line looks like this. Log.d("MyTest","== MyEnv " + System.getenv("AP") + " ANDROID_ASSETS:" + System.getenv("ANDROID_ASSETS"));

Before I execute my code I define my AP variable with export: export AP="12345" and the this is my output of set command

ANDROID_ASSETS=/system/app
ANDROID_BOOTLOGO=1
ANDROID_DATA=/data
ANDROID_PROPERTY_WORKSPACE=9,32768
ANDROID_ROOT=/system
AP=12345

Then I execute my code and I get this line from logcat

D/MyTest( 5363): == MyEnv null ANDROID_ASSETS:/system/app

The value for my defined Environment variable is null. Any suggestions on why it didn't work?

View 1 Replies View Related

Android :: Development Mode And Maintaining Environment Variables

Nov 16, 2009

I'm building an Android application and would like to maintain a few environment variables that I can tweak depending on whether I'm in development mode or release mode. For example, I need to invoke a web service and the URL will be slightly different in either mode. I'd like to externalize this and other settings so I can change them easily based on my target deployment. Distinguishing development mode and release mode environment settings on Android. Are there any best practices or anything in the SDK to assist with this need?

View 3 Replies View Related

Android :: All Static’s Variables Retaining Values When Launching Again

Dec 1, 2009

I have been facing problems to manage statics variables used in my android application. If we exit the application against a particular event (touch or key event -which is must for my app), all the statics variables are retaining the values when I am launching it again. I am invoking Activity.finish() method for termination . I know there is a collection type class available called Bundle and we can use it to save the states of all the statics and get those back when again creating the same activity during relaunch, but it would be a hard task if we want to port some j2me applications to Android because of having thousands of statics variables. Is there any way to kill the application completely including all the statics variable used there?

I tried with System.exit(0) and it works well for Android G1 and G2 (tested in firmware 1.6). But in Android Robyn (prototype) the same causes a major defect ("Activity not responding" popup apears just after exit) and I came to know from android dev forum that calling System.exit(0) is not recommended for termination of an activity.

View 3 Replies View Related

Android :: Parsing XML And Initializing Static Variables Of Some Class

Dec 21, 2009

I have an application that is driven by a configuration XML: various app properties are loaded at the app start-time by parsing the XML and initializing static variables of some class. The data read from this XML drives different Activities of the application. Presently, I have called the "parsing and the properties-initialization" from the onCreate() of my Main Activity. I have a few questions as regards this case/approach: Should I invoke the app initialization method from the Application Object or is the current approach correct?

What advantages/disadvantages do/would we get/have if I choose to invoke it from the Application object? Do we really need a static class to store app properties? Or can we have all the properties as a static Collection variable in the application object? Parsing a XML(~200 nodes) at app load time might take some time (not sure how long tho); How can I avoid the dreaded ANRs? I am using a Pull Parser.

View 2 Replies View Related

Android :: Reason Not To Use App Class To Share Variables Across Activities?

Dec 31, 2009

Is there any reason not to use the Application class to share variables across Activities? For instance a handle to the DB or a single HttpClient.

View 2 Replies View Related

Android :: Accessing Environment Variables By The Running Process

Mar 3, 2010

I want to know if there is a way to pass environment variables to the running process in Android. If yes, how should one set those environment variables.

View 4 Replies View Related

Android : Store Values Of Variables To Access On Other Tabs?

Jun 9, 2010

I'm kinda noob to android so please bear with me. I'm currently developing app which uses tabs. My question now is: how to store values of variables so I can access them on the other tabs? I want to create something similar to sessions in PHP where I can save variables on one page and access on the other.

View 4 Replies View Related

Android :: Sharing Global Variables Across Activities - Problem When Using Webview

Jun 23, 2010

I'm sharing some variables accross activities by using a class like this :

CODE:..........

Then I'm using these variables anywhere across my multiple activites with ...if (Globals.hint2_stockview_valuation == false) {....}

Pretty basic and it was working fine untill ...

I introduced some webview stuff like this:

CODE:...........

And here's the News_Webview.class:

CODE:............

The problem now is that, when it "comes back" from this Activity, it looks like my Globals variables have disappeared ?

if (Globals.hint2_stockview_valuation == false) {

fires an error :

06-23 12:14:03.443:
ERROR/AndroidRuntime(2611): Caused by:
java.lang.NullPointerException

2 Questions then:

Should I use something else than this "Global" class to share variables across activities ? Is it just bad practice to do this ?? I know that I can use the preferences but I thought it was quicker to do it this way (no need to "read" the preferences everytime I start a new activity ...Should I "get back" my savedInstanceState in some way when my activity returns from the News_Webview.class ?

View 2 Replies View Related

Android :: Previous Set Instance Variables Null When Activity Resumed

Apr 20, 2010

I am using an Application object to store app-wide instance data--data that I need to remain in existence for the entire lifetime of the app, so the Application class seems like the proper place to put it. I have just finished reading this thread http://groups.google.com/group/android-developers/browse_thread/threa... that goes into pretty good detail and receives confirmation from Googler hackbod as to how the Application class performs--and from that info it seems this strange behavior I am receiving should not be happening...

Basically, every once in a while when I resume my app in any of its Activities (it is still running in memory so onCreate is not called) I get NullPointerExceptions because instance variables in my Application class are returning null when I request them from my Activity (via a getter method in my custom Application class). It seems as if sometimes Android saves the states of my Activities but deletes all my instance variable data... This can't be an Android problem--there must be something wrong with my code.

Has anyone else ever ran into an issue of this kind? Any ideas as to what may be causing this? I'm not going to post my code here as that won't help anyone, but hopefully someone can point me in some helpful directions.

View 11 Replies View Related

How To Declare URL Variables

Aug 4, 2012

how do i declare URL variables

i tried this, but the "URL"s are marked as errors

Code:
URL url = new URL("URL.goes.here.com");

URL cannot be resolved to a type, is what eclipse tells me

View 2 Replies View Related

Android :: Most Of Droid Tutorial's Variables Start With M / Is This A Java Thing - Stand For Mobile?

Jan 19, 2010

I know about camel case rules, but I'm confused with this m rule. What does it stand for? I'm a php developer, "we" use first letters of variables as indication of type, like 'b' for boolean, 'i' for integer and so on.

Is 'm' a java thing? Does it stand for mobile? mixed?

View 3 Replies View Related

Android :: Static Variables Of An ApplicationContext Subclass Left Untouched When The Process Is Killed?

Sep 7, 2010

Do static variables of an ApplicationContext subclass left untouched when the process is killed?

View 4 Replies View Related

How To Pass Variables From Service To Activity

Aug 30, 2012

how can I pass variables from service to activity and vice versa?

View 1 Replies View Related

How To Generate And Use Variables In Different Switch Statements

Jan 29, 2012

I'm trying to encrypt a text with DES algorithm using Bouncy Castle library. I have written the following code:

Code:

try{
KeyGenerator kg=KeyGenerator.getInstance("DES");
SecretKey key=kg.generateKey();

[Code]....

Then depending on the user selection, inputText is encrypted or encText is decrypted in the switch statement. Both encryption and decryption blocks share the same "keySpec" and "Cipher" variables generated in the above code snippet. However, the compiler says that keySpec and Cipher cannot be resolved which I understand is that the keySpec and Cipher generated cannot be seen by the statements inside the switch blocks. How can I make it work?

View 5 Replies View Related

General :: ADB Can't Open Files From Folder Used In System Variables

Feb 13, 2014

I have installed ADB and the whole Android SDK to root my asus transformer infinity (tf700t). I have taken all the steps every forum on the web describes: installing everything trough the manager, adjusting the path in the System Variables, and finally it getting it to work together with my tablet. However, when I try to flash/copy/install files from my folder (yes these files are in the same folder as adb.exe and fastboot.exe, which is the folder I used in the System Variables) It can't either find these files or it cannot open these files. When i put in the command 'path' however. I does give me the path where the files can be found.

View 1 Replies View Related

Android :: Want To Use Accessibility Classes

Oct 29, 2010

I want to use the accessibility classes, but I'm a begginer in android programming and i can't understando how to use them. I don't find any example using these classes. Somebody can give me some use examples? Another thing Can I set enable the Accessility mode in the emulator?

View 2 Replies View Related

Android : Need Dynamic Classes App

May 18, 2009

I am writing a app, which has sort of plugin framework. public abstract class AbstractService {public abstract AbstractService getInstance(String name)..

View 2 Replies View Related

Android : Get Classes In An Apk Using DexClassLoader?

May 29, 2009

I have an apk installed in /data/app. I want to use the class methods in there. Here is what I tried. code...

I got "ClassNotFoundException". By peeking into the apk, I don't see class files but classes.dex. I would assume SystemProperties class is in classes.dex. Why can I load it?

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved