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.

Android :: Reason not to use App class to share variables across Activities?


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 :: 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 :: 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 :: 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 :: 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 :: Service By Mean Share By All Activities

Aug 27, 2010

Android: i want to create service by extending a Service class which i start when application get started and all activities can share its state and when i want stop it from other activity and when i want start it again from any activity ?

View 1 Replies View Related

Android :: Share Preference Across Several Activities?

Feb 14, 2009

I have two activities in two different packages: com.foo.a and com.foo.b. Is it possible to create an PreferenceActivity (with the exact same XML file) so that the preference is shared across the two activies?

View 2 Replies View Related

Android :: Share A View Across Various Activities?

Jul 1, 2010

Is there any way to share the same object of the View across various activities? For example myApp has 4 activities, and every activity shows a Logo at the top of the screen. Now each activity will initiate 4 copies of the same Logo. So is there any way to get around this? And if 3 out of 4 share the same logo?

View 1 Replies View Related

Android :: ViewFlipper Not Working Inside A Class Which Extends LinearLayout / Reason Of It?

Apr 22, 2010

When I tried to create a ViewFlipper inside a class which extends LinearLayout, its throwing an exception

"java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()".

I am creating the ViewFlipper using,

ViewFlipper flipper = new ViewFlipper(ctContext);

But when I create the ViewFlipper in a class which extends Activity, its working normally. What may the reason?

View 3 Replies View Related

Android :: Many App Share One Class?

Aug 2, 2010

I want many app share one class, for example,I have MessageVo,I want testApp and testTwoApp share MessageVo.but I don't know TestTwoApp use MessageVo.

View 6 Replies View Related

Android :: Share SQLite Database Across Multiple Activities?

Jul 20, 2010

I am developing an app which requires me to write to an SQLiteDatabase in one activity and access it from another activity . I am facing a problem implementing this. Any suggestions/ideas as to how we can share the database across multiple activities?

View 2 Replies View Related

Android :: Share Files With Different Activities Running / In Different Processes In Application

Mar 16, 2010

I would like to share a cache file across activities, which are running in different processes but in a same application.So, is there any way to make it thread safe (probably not "thread safe", should we call it "activities safe" or "process safe" ?

View 2 Replies View Related

Android :: Singleton Objects To Save State Or Share Data Between Activities?

Nov 24, 2010

It would be nice if StackOverflow had a section where we could post tutorials like mine so that I can answer literally hundreds of questions that have been asked here with a single blow. See... every day I read questions about how to pass complex objects between activities, how to save state so that your app can resume after orientation change, how to update listviews when the data changes, etc, etc. Here is the second part of a tutorial series I posted on my blog... I hope that you actually read it... because I haven't seen any examples like it anywhere... and it has changed how I think about developing for Android across the board. The question is... is there a downside or negative affect of developing like this?

Beyond Smart Lists - How Observable Singletons change the game. Please read through both of these tutorials carefully... I will answer any questions about it here that I can... I really want to know what you think about this and if it might solve issues for you. NOTE TO MODERATORS: there are no advertisements of any kind on my blog.. so don't just close this because you think I am spamming somehow... I am not going to duplicate my post here.

View 1 Replies View Related

Sprint HTC Hero :: Share How You Use Your Screens /share Pics

Jan 5, 2010

I am just wondering if anyone would like to share pics of how you have you 7 screens setup.

View 49 Replies View Related

Android :: Switching Activities / Passing Data Between Activities

Jun 30, 2010

how to call BarCodeScanner, and return the value to a field.so now, i have a toast that says "successful scan" and then i want to pass the result to a new activity. when i comment out my intent, everything works (minus the passing of data/switching of screen, obviously) but when i run my project as is, it FC's no errors reported by eclipse in code or xml. any insights?

View 2 Replies View Related

Android :: Creating A New Class Using Eclipse New Java Class Dialog Box

Jul 7, 2010

I'm creating a new class, using eclipse "New Java Class" dialog box. I can write the superclass I want (I can't find using "browse" button), but I can't write or select an interface to implement. I click "add" but ther is nothing to select. What I'm doing wrong?

View 4 Replies View Related

Android :: Communicating Between Receiver Class And An Activity Class

Jul 14, 2010

I'm just getting into Android development, and I have a question about communicating between a receiver class and an activity class. I'm very new to JAVA and Android so I hope I don't sound too stupid. I'm developing an application where I intercept an SMS message and then based on various elements of that SMS I might delete it once it's been saved to the inbox. I have a receiver class that intercepts the txt message, and I am also able to delete messages from my inbox with code in the activity class using a button at the moment. The problem I have is communicating between the receiver class and the activity class where the code to delete a message resides. I tried putting that code directly into the receiver class but as I'm sure most of you already know the BroadcastReceiver class doesn't seem to support what I need to delete messages. I've been searching for an answer to this for a while, but haven't been able to find anything. Honestly I'm not sure I know enough about JAVA and Android to even recognize a solution if I saw it.

View 2 Replies View Related

Android :: Accessing Class Level Stuff From Inner Class

Jun 27, 2010

What I want to do, is be able to access the object neoApi inside the Neoseeker class, from its inner class RunningTimer. Now, in my code, you can see what I would think to work, but when I run my application, nothing pops up. Nothing inside my TextView, no Toast, nothing at all. How can I remedy this?

package com.neoseeker.android.app;
import java.util.Timer;
import java.util.TimerTask;
import org.json.JSONObject;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;.......................

View 1 Replies View Related

Android :: Access Application Class From Class Other Then Activity

Sep 8, 2010

I'm new to Java and android development. In my application I need data which is accessible for a few activities. I've read that a good solution is to use Application class for this. So I use it like this:

public class MyApplication extends Application {
private String str;
public String getStr(){
return str;
}
public void setStr(String s){
str = s;
}
}

and I can access this variable from activity like this:........................................

View 2 Replies View Related

Android :: Call Activity Class From Other Java Class?

Oct 8, 2010

I have just started android. I just want to know that how can i call activity class from other java class. i just want to pass class object to activity class.

public class GsonParser extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MagazineThread thread=new MagazineThread();
thread.start();
}
public GsonParser(JsonMagazineParser Obj)
{

}
}

and i am just doing like from other class. GsonParser obj=new GsonParser(this);passing obj to activity class.how can i achieve that.

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 :: 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 : 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..

View 2 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 :: 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 :: How To Run Class In Background Among Package Of Class?

Apr 23, 2010

In my app in one package there are some classes. from those classes i want to run one class that is the Gps functionality class. i want to run that class in background. how i do it, i don't know. i am not able to make it solve from any document. if anybody knows the way to solve it please me by run a "hello world" app in the background. i am not able to solve this problem by going through document.

View 2 Replies View Related







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