Android :: Static Vs Non-static Inner Classes

Mar 9, 2009

I have been finding it convenient to extend Handler in many of my activities to handle messages specific to the activity. The handler sublass is an inner class of the activity and needs to access its state. I am wondering if there is any performance difference between making the handler subclass static and passing in the activity explicitly in its constructor or making the subclass an "instance class" and letting the vm worry about my accessing members of the containing activity.

The static approach:

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

Android :: static vs non-static inner classes


Android :: Avoid Non Static Inner Classes In Activity?

Jun 17, 2010

Since I seem to have caught two activity references in a heapdump, where the Activity is set to singleTask. Romain's advice on avoiding memory leaks includes: "Avoid non-static inner classes in an activity if you don't control their life cycle, use a static inner class and make a weak reference to the activity inside"

What does this mean exactly? I can't find any examples, positive, or negative for this rule. I do have some non static inner classes in my activity. Most of them are anonymous inner classes like this one. I see hundreds of them in the samples:....................

View 24 Replies View Related

Android :: Call Non Static Method In Static SQLiteDatabase Class

Mar 30, 2010

i want to display a msg to the user (msg box or Toast) when exception happend in a static SQLite Database class that i use. the problem is that i cant call a non static method in a static class , how can i handle this. this is the class

private static SQLiteDatabase getDatabase(Context aContext) {

and i want to add something like this in the class when exception happen but context generates the problem of reference to non static in static class.

Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();

View 1 Replies View Related

Android :: Cannot Make Static Reference To Anon-static Method

Feb 7, 2010

I'm having some issues with the old "Cannot make a static reference to a non-static method" error in my Android program. I am creating a sand falling game (similar to the Powder Game) and I created a class called Control to create a Control Bar at the bottom of the screen with a slider for brush size (that works fine) and a button to pop up a Dialog to allow users to pick the selected element. However, when I call DemoActivity.showDialog(2) from my code, it gives the static reference to non-static error (DemoActivity is the main activity of my application). I also tried changing it to just Activity.showDialog(2), but I got exactly the same error!

Here's my code:

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

I fixed it by adding the following to my Control.java code:

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

And then calling control.setActivity(this); from my onResume section of DemoActivity.java!

View 2 Replies View Related

Android :: Non-static Method Cannot Be Referenced From A Static Context

May 26, 2010

I am modifying the source code here: http://thinkandroid.wordpress.com/2009/12/30/getting-response-body-of-httpresponse/

I get this error:

code:.............

This error is line 13 on the second box.

View 5 Replies View Related

Replace Single Row View In Custom STATIC ListView - STATIC Data

Mar 18, 2013

I have Eclipse Juno and I'm working on an app with that.

The main activity will have a scrollable menu that takes you to all the other activities.

So the general structure/outline right now:[HIGH]Relative Layout ImageView (header logo type thing) ListView (the actual scrollable menu)[/HIGH]Here's the problem though... I can't find any simple list tutorials. I can easily make a single line list work but I need to make a two line list and one that is static, not dynamic and no examples are out there for that. It's like if you want to make a 2 line list, you can only learn how to do it in the most code-heavy ridiculous way possible.

Essentially what I am looking for with the list is this: Item one: Centred, bold, non selectable title (Resources)

- Item two-??: two line list items, click-able to a new activity, title of the section on first line, description on the second line.

- Item ??: Centred, bold, non selectable title (Tools)

- Item ??-??: two line list items, click-able to a new activity, title of the section on first line, description on the second line.

Nothing dynamic that is ever going to change, no super complex wonkey calculations, just to simply have the data set in stone (preferably via XML) and to call it into the list.

I experimented with some of the other list views and no matter what I did, I could get, via editing the resources and NOT using Java, more that one item on a single line but it wouldn't format it properly according to the layout I guess because I haven't got the ID correct or whatever I don't know.

I mean, all the examples I've seen for a 2 line list are extraordinarily over-coded and just bloated. I mean I have a website I am still working on in C#/ASP.net that has far more complex things in it with half the code that I've seen for the examples of the two line lists.

I tried on my own to figure it out (I am decent with C# and vaguely familiar with Java, self taught, and programming for some other systems like Python, again all self-taught), but like ALL coding references, they're organised by the actual code you implement (that you don't know) instead of by what you want it to do (so you have to search the whole code base to find something that you don't know what it's called but know what it does). >:C

View 10 Replies View Related

Android :: Static Fields In Activity Classes Guaranteed To Outlive Create / Destroy Cycle?

Oct 28, 2009

I frequently run into the problem that I have to preserve state between several invocations of an activity (i.e. going through several onCreate()/onDelete() cycles). Unfortunately, Android's support for doing that is really poor. As an easy way to preserve state, I thought that since the class is only loaded once by the class loader, that it would be safe to store temporary data that's shared between several instances of an activity in a static Bundle field. However, occasionally, when instance A creates the static bundle and stores data in it, then gets destroyed, and instance B tries to read from it, the static field is suddenly NULL. Doesn't that mean that the class had been removed and reloaded by the classloader while the activity was going through a create/destroy cycle? How else could a static field suddenly become NULL when it was referencing an object before?

View 2 Replies View Related

Android :: Why Does Android Prefer Static Classes

Jun 24, 2010

I see a lot of Java code where android prefers to have developers use static inner classes. Particularly for patterns like the ViewHolder Pattern in custom ListAdapters. I'm not sure what the differences are between static and non-static classes. I've read about it but it doesn't seem to make sense when concerned with performance or memory-footprint.

View 5 Replies View Related

Android :: Static Method In Java Accept Only Final Or Non Final Variables Within Its Method - But Not Static

Sep 15, 2010

Why should a static method in java accept only final or non final variables within its method, but not static?

For example I have the following method:

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

View 6 Replies View Related

Android :: Static Way To Get Context

Jan 4, 2010

Is there a way to get the current Context instance by using a static method? I'm looking for that way because i hate saving the context instance each time it changes.

View 1 Replies View Related

Android :: Static Compilation

Sep 11, 2009

I was working on Freescale iMX31 board, I ported android and it was working fine , but when it came to integration of WiFi & Bluetooth, android forum recommended me to do static compilation for porting over android !

Can I know why some drivers have to be statically compiled before it is ported over android? It was not the case with other drivers which when integrated with android, they worked perfectly well like serial port, usb etc..

View 2 Replies View Related

Android :: Is The Static Safe ?

Jul 29, 2009

I use a single static class in my code that defines a static field which I'm reusing between Activity onStop/onStart invocations. Here's a scenario:

User clicks on "Authorize" button (static data is initialized) Activity is stopped and web browser is called
Browser executes callback and Activity is restored (static data is reused)

At least one of my users reports the failure at step 3 which I cannot reproduce but which looks like reset of static data.

View 1 Replies View Related

Android :: App Static Storage ?

Sep 30, 2010

I am creating an Android application which will have some embedded music inside of it ( ~ 80 MB ). I was planning on putting it in the res/raw folder.

Since android stores that all in it's internal memory, is this way too large? What are my options? I have come up with the following:

Copy resources out of internal storage and onto the SD card when application first starts. Afterwards remove from internal storage (is this possible?)
Download music from the web when the application first starts.

I would really prefer not to have to go with option 2 since I want the app to be entirely offline and the static music is not going to change (except between releases).

View 2 Replies View Related

Android :: Mic Audio Capture Too Static

Jun 3, 2009

As a first step toward a speech recognition project, we wrote a simple voice recording application based on the information in this thread:
http://groups.google.com/group/android-developers/browse_thread/threa...

It is working; however, the audio is extremely poor too static for our needs. As a comparison, we did a similar audio file captured with audacity on a PC and it was much better. Has anyone been able to record high quality audio with the android dev phone? According to the documentation of MediaRecorder, there is only one audio encoder "AMR (Narrowband) audio codec" and three output formats--3gpp, mpeg, and raw AMR:
http://developer.android.com/reference/android/media/MediaRecorder.html

According to wikipedia, AMR encoding is only 8hz. Is there a better option available perhaps a lower-level API compared to MediaRecorder? We are testing on Windows XP, with a Logitec USB microphone, eclipse ganymede, and we are using all the defaults for an android 1.5 app (no emulator command-line options. We defined the SD card in AVD manager).

View 2 Replies View Related

Android :: The Life Cycle Of Static

Mar 7, 2010

When starting a new Activity, I want to pass a complex object and do so by using this approach:

MyActivity.COMPLEX_OBJ = myComplexObj; // which is definitely NOT NULL! Intent intent = new Intent(); intent.setClass(this, MyActivity.class); startActivity(intent);

and then in MyActivity:

@Override public void onCreate(Bundle bundle) { if (COMPLEX_OBJ == null) { // report to Flurry ... } ...

}

View 17 Replies View Related

Android :: Static Variable Instantiation

Apr 1, 2009

I have noticed in my application(s) that after a call to Activity.finish() that the static variables that I declared in my classes still hold the values that they were changed to during the activity's life cycle. Upon the re-launch of the activity, the program does not re-instantiate the variables as declared or set them to the default java behavior. Is there something that I can do to cause this to happen, other than re-setting every static variable in my application?

View 3 Replies View Related

Android :: Static Layout For Whole App That Must In All Activity

Nov 17, 2010

Static Layout for whole app that must be in all Activity

View 12 Replies View Related

Android :: Use Of Static Finals In Activity

Sep 8, 2010

Why is the use of static final variables encouraged to declare constants over just final variables? The use of static sounds logical when there will be many instances of a class but is this argument correct when used for a Android activity. In fact, since the Class instance will be around even after the activity finishes and is eventually garbage collected, it seems like all these constants will still be in memory until the class loader is around. Also, does the compiler inline non-static final variables(ints and String) just like it does for static final variables?

View 2 Replies View Related

Android :: Static Context Access

Feb 15, 2010

I'm trying to handle exceptions at a global level. My understanding is that the only way to do this is with an UncaughtExceptionHandler. However, this reduces one to the primitive java file and network i/o packages. I'd like to be able to broadcast an intent or bind to a service. Is there some way to interact with the android packages to retrieve a context in a static manner? I could probably do some hack workaround with a thread local, weak-referenced context set at the time of the exception handler, but I'd rather avoid that nastiness.

View 4 Replies View Related

Android :: Static Header In ListView

Jun 12, 2010

I have a ListView with several columns and I need a header row at the very top that labels each of these columns that *does not* scroll with the rest of the ListView. I am using addHeaderView right now, but I've ran into 2 problems:

1) The header scrolls. I need it outside of scrolling so that it's always "floating" on top.

2) Each column in the header isn't lining up with the columns in the listview. I can make the header columns and data columns all line up perfectly if they're all in one big TableLayout, but how would I get the header to be outside of the scrollview yet also stay uniform and inline with the data columns?

View 8 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 :: Pitfalls When Using Static Functions?

Sep 30, 2010

I use in the getView()-Method of this example a static function to download the source of an ImageView. Later there will be threading included. However, I like to know in general how save the use of static function is in this case.

Because I experienced, that in some cases (when I scroll really fast) the Images get mixed up.code...

View 3 Replies View Related

Android :: Use Static CreateBitmap Method?

Jun 23, 2009

My application crashes after I try to use the static Bitmap createBitmap method to get a mutable bitmap in order to fill it later with data.

If I only create one 1024x1024 the application works just fine, but when I try to load the same image more than once (first making my object null in each round) my application crashes on my third or fourth try.

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

View 4 Replies View Related

Android :: Storage Of Static Data Within App

Jul 28, 2010

I am currently developing a simple info app on various uni campuses. I want the app to operate predominantly in an offline state thus I want to store all my information locally. The data within the app will not be subject to any change thus I was wondering what the best (practice) method was to store such data? Basically should I be storing the info in a SQLite db, java file or xml?

View 3 Replies View Related

Android :: Put Static Route Into System

Sep 2, 2010

I currently have a moto droid, and am thinking about getting a android tablet when they mature a bit. My concern is i want to use this at work, but for this to be completly functional i need to put a static route into the system. We have a wireless network which is seperate from our wired by a router. It is all static IP based and so on to keep employess off the internet, but if you know what static route to put in you can access the systems on the wired network. Does anyone know if this is posible, i have tried looking at the system files via Astro and i havent found anything.

View 2 Replies View Related

Android :: Utility For Storing A Static Map?

Feb 19, 2010

I've got a common use-case wherein a user selects one item out of many (say, on a spinner or autocomplete list), then enters the data. For example, let's say the user selects a country. Ultimately, the data I want is the country code, not the country name; but the users will want to select based on name, not code. To put it another way, user's will select "United States", but I ultimately want that to translate into "US".

There are a lot of countries. Is there an easy way to setup a mapping in Android to hash from the name to the code? I've thought of a few solutions, none of them are quite satisfactory in my mind:

A database containing country/code, which I can query on. Setting up all countries as strings in strings.xml, then retrieving the resource by name. Creating a huge Map in code and using that. (This is the least satisfactory answer).

View 2 Replies View Related

Android :: How To Add Static Row In List View

Mar 17, 2010

How to Add Static row in list view. I have a requirement where i need to add the Static row as first row in list view.

View 2 Replies View Related

Android :: How Would I Make A Web Viewer With A Static Image?

Aug 8, 2010

I am interested in making an application that does various things, but I am having trouble getting a static image, such as an avatar off of a web page.

View 1 Replies View Related

Android :: Headphones For My Cell Cause Static For People On Other End?

Aug 9, 2010

For example whenever i call my girlfriend and I try to use my head phones so I don't have to hold up my phone she says there is a lot of static that's really loud and hurts her ears

View 1 Replies View Related

Android :: Can Static Library Created By 2.0 Work At 2.1?

Mar 8, 2010

I create one static library(alogrithm.a) by using android 2.0. Now I want to use this library to work at android 2.1. Can I rebuild source code to create at android 2.1? Or directly use this library binary file by creating android 2.0?

View 3 Replies View Related







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