Android :: Activity Constructor Vs OnCreate

Jul 21, 2010

I understand that Android Activities have specific lifecycles and that onCreate should be overridden and used for initialization, but what exactly happens in the constructor? Are there any cases when you could/should override the Activity constructor as well, or should you never touch it?

I'm assuming that the constructor should never be used because references to Activities aren't cleaned up entirely (thus hampering the garbage collector) and that onDestroy is there for that purpose. Is this correct?

Android :: Activity Constructor vs onCreate


Android :: Pass Enumerators To An Activity Constructor From An Intent?

May 14, 2010

I have an activity that when started needs access to two different ArrayLists. Both Lists are different Objects I have created myself.

Basically I need a way to pass these objects to the activity from an Intent. I can use addExtras() but this requires a Parceable compatible class. I could make my classes to be passed serializable but as I understand this slows down the program.

What are my options?

Can I pass an Enum?

As an an aside: is there a way to pass parameters to an Activity Constructor from an Intent?

View 3 Replies View Related

Android :: What Is The Significance Of Context In Various Constructor Of Intent Class When Starting An Activity

Mar 4, 2010

I had come across a code snippet which calls for an activity without referring to any context. Before, i was considering that context is used to tell about the calling component. But as i came see that another component can be called without any reference to context, it makes me wonder what purpose it might be serving. please put some light on it.

Here is the code which calls for an activity without referring to 'context'

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

View 1 Replies View Related

Android :: Closing An Activity On OnCreate

Nov 11, 2010

I'm opening an Activity using this:

startActivity(new Intent(Parent.this, Child.class)); And on the child, I have this code on the onCreate function (the if contains more than just true, of course): public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState); if (true) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setPositiveButton("OK", null); builder.setTitle("Error"); builder.setMessage("Connection error, please try later.") .show(); finishActivity(0); return;}}

Why is the activity not closing? I get the alert box, but then I have to tap the "back" button to go back.

View 2 Replies View Related

Android :: Database Activity OnCreate()c

Nov 19, 2010

I know that network activity and expensive operations should not be done on the ui thread, but what about database activity?

I have an activity that, when started, I query an sqlite database and dynamically populate rows in a tablelayout with an inflator. I do this all in the oncreate() method. Should this be done in a separate thread?

View 2 Replies View Related

Android :: Oncreate - Intent Launches My Activity

Sep 30, 2010

Android will call onCreate() of my activity whenever it is launched.

In the onCreate() of my activity can I tell what intent launches my activity?

View 1 Replies View Related

Android :: How To Do A WebView / ListView In Same Activity OnCreate?

Feb 10, 2010

As you can see, I first create a webview. Then, I want it to immediately disappear. Then, I want the Listview to come up. But the problem is, I can't do Listview if I don't do ListActivity but then I can't do Activity. Code...

View 2 Replies View Related

Android :: Parent And Child Activity OnCreate?

Jul 2, 2010

I have a parent activity, and a child activity that extends the parent activity. When the parent starts the child activity,

Which onCreate gets executed first? The child's or parent's?

There is a particular variable I am setting in the Child activity's onCreate method, and right now, it looks like it takes a while to get to the Child activity's onCreate, and so the methods in the Parent are reporting an empty variable. Whereas when I make the Parent sleep for a while, it reports the correct variable.

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

So, basically, even after the Parent starts the Child, it still returns "Parent Value", but when I have the thread sleep, it return "Child Value".

View 1 Replies View Related

Android :: Opening A Context Menu In OnCreate Of An Activity

Aug 9, 2010

I have a need to capture some user input when an activity opens for the first time. I'm hoping to give the user a list of options to select from, which will be pulled in dynamically. I'll then store the selected value locally for future use. I'm not finding a way to do what I'm after and was wondering if anyone has run into this before and how they solved it.

Fantasy Football<http://chriswstewart.com/android-applications/fantasy-football/>- Android app for fantasy football fanatics and MFL owners Social Updater<http://chriswstewart.com/android-applications/social-updater/>- An easy way to send your status blast to multiple social networks

View 9 Replies View Related

Android :: ExpandableListView - Exception In The OnCreate Method Of An Activity

Mar 3, 2010

I am encountering an exception in the onCreate method of an activity.

CODE:.......

The onCreate method is as below.

CODE:......

The layout view XML is as below.

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

I've already changed the ID of the ExpandableListView to "list". But it is not effective.

View 4 Replies View Related

Android : Webview - OnCreate Always Get Called When Activity Comes To Foreground

Mar 29, 2009

I launch my TestWebView activity. After my web page is loaded, I put the app in the background by pressing the Home key. Then I bring the TestWebActivity back to the foreground. Unexpectedly, TestWebView's onCreate() is called when I bring the activity to the foreground. But onDestroy is never called. This same thing happens every time I tested. It appears the old TestWebView was not completely killed so there are possibly duplicate web clients running.

My code: .....

View 7 Replies View Related

Android :: Can't Call Service Function In Activity's OnStart / OnCreate?

Sep 28, 2009

My activity bind a service. I want to call the service's function in activity's onStart/onCreate function, but it doesn't work. The service started sunless but the connection is null. When I just call the service's function in other function (onClick for example),

View 4 Replies View Related

Android :: Parent Activity Runs OnCreate Before OnActivityResult Is Called - Sometimes

Aug 5, 2010

The order is:

A: startActivityForResult( B ) B: <dostuff>, call finish() A: onCreate <---- what's this all about A: onActivityResult

This happens for a tiny minority of users. I havn't been able to reproduce or find any common elements. A is the launch activity.

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

View 7 Replies View Related

Android :: Activity Execute OnDestroy() / OnCreate() Method When Push On Keyboard

May 2, 2009

I use sdk 1.5 version and same to my handphone, my handphone is use G1. Now i test my application on my handphone. When i push on keyboard, i found system will destroy current activity(execute onDestroy() method) and execute onCreate() method again. So i will all current status and all datas. I don't wish this happen, how to block system execute onDestroy() and onCreate() when i open and close keyboard?

View 2 Replies View Related

Android :: Check Condition Inside OnCreate() Of Activity And Display An AlertDialog?

Aug 18, 2010

I am new to Android and this is my first question here so please go easy on me.

Is it possible to check some condition inside onCreate() of an Activity and display an AlertDialog?

I am creating an AlertDialog anonymously in Oncreate() and calling show on that instance but the AlertDialog is never displayed.

View 1 Replies View Related

Android :: Voice Recognition Activity Called In OnCreate Method / Causes App To Load Slowly

Oct 1, 2010

In my android app I call the voice recognition in my onCreate method of my startup activity. I have made it a preference to start up with the voice control or not. However, the app takes about 5-7 seconds to load when voice recognition is on. When it is off, the app starts almost instantly. Below is sample code, I have added Free_Form, max_results 1, and a custom prompt to mine.Why would calling the normal android speech recognition take sooo long to load in my OnCreate method?

View 1 Replies View Related

Android :: NinePatchDrawable Constructor - Chunk And Padding

Mar 2, 2009

I am trying to create a NinePatchDrawable programmatically, but there is no documentation on the constructor's argruments (Bitmap bitmap, byte[] chunk, Rect padding, String srcName). Does anyone know what chunk and padding are... and how to specify them?

View 7 Replies View Related

Android :: Subclass Of View Constructor Not Being Called

Jun 6, 2010

I'm subclassing Android's view class, but whenever I make an instance of the view from another class, the constructor never gets called (or so it seems). I've implemented both public myclass (Context context) and public myclass (Context context, AttributeSet, attrs) I can't figure out what I'm doing wrong. Do I need to override onDraw and onMeasure?

View 1 Replies View Related

Android :: Calling Superclass Method In Subclass Constructor

Apr 30, 2010

I get a NullPointerException calling a Superclass Method in Subclass Inner Class Constructor... What's the Deal?

In my application's main class (subclass of Application), I have a public inner class that simply contains 3 public string objects. In the parent class I declare an object of that inner class.

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

After I instantiate the object in the constructor, I get a runtime error when I try to assign a value in the inner class with a superclass method.

Can you not call superclass methods in the subclass constructor?

View 3 Replies View Related

Android :: Class Derived From Intent Service Must Have Default Constructor

May 8, 2009

I'm posting this to share the lessons I learned while working with IntentService. IntentService has a single constructor that takes a string argument "name". The documentation has no description of what name is used for. In looking at the sources, I found that its only use is in naming the worker thread for the IntentService. This thread is named IntentService [name].

I initially implemented the constructor of the derived class to also take a String argument and passed it along to the derived class. This is wrong. This will cause the startService() call to generated a java.lang.InstantiationException in the application containing the service i.e. you don't get the exception in the application calling startService(). A clue to the actual problem is a little further up in the logs:"newInstance failed: no <init>()"

The derived class must have a Default constructor and that constructor must call super() passing a string for the name component of the worker thread name.
public class MyIntentService extends IntentService {
public MyIntentService() { super("MyIntentService");
} @Override
protected void onHandleIntent(Intent intent) {
// Handle events on worker thread here }

View 2 Replies View Related

Android :: How To Use Parcelable - If Class Requires Additional Parameters In Constructor

May 20, 2010

I'm trying to create class with generics that will have ability to serialize its state using Parcelable interface.
The problem is that class has to contain constructor with single parameter - Parcel, but in my case I need to create class with additional parameters.
Besides, Parcelable.Creator doesn't allow to use generics.

Here is an example:

public class Sample<T> { ...

public Sample(Context ctx, SomeInterface iface, Parcel parcel) {...}

...}

What is the best practice to do it?

View 1 Replies View Related

Android :: Retrieve Saved State Of Custom View In Constructor?

Oct 12, 2009

The "View" instance currently provides a way to retrieve the saved state using the methods below, but there doesn't seem a way to retrieve the view's saved state in the constructor, or onFinishInflate. The custom view is constructed via XML, so I cannot pass the saved bundle from the Activity to the View's constructor.

Relevant methods: - protected Parcelable onSaveInstanceState() and - protected void onRestoreInstanceState(Parcelable state)

I need this because I make an asynchronous network request in a custom view constructor, and if there is a configuration (orientation) change, the custom view is getting reconstructed, and the request is getting performed again. I want to intercept the second request in the constructor. I can do this in the onRestoreInstanceState, but I need to handle this in the constructor.

It would be nice if there was a method such as getSavedState so that the decision can be made in a constructor or onFinishInflate instead of waiting for the onRestoreInstanceState trigger.

View 3 Replies View Related

Android :: Dalvik Message - Default Buffer Size Used In BufferedInputStream Constructor

Aug 17, 2010

When I used BufferedInputStream and I specify a buffer size, Dalvik gives me this warning - Default buffer size used in BufferedInputStream constructor. It would be better to be explicit if an 8k buffer is required.
But right now, my buffer size is already at 8k. What am I doing wrong?

View 1 Replies View Related

App Crash Every Time Try To Call Constructor Code From Map Class

Oct 10, 2013

I'm developing an app that uses google maps, but for some reason it crashed every time I try to call the constructor code from the map class.

main
[HIGH]import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {

[Code] ......

View 2 Replies View Related

Android :: OnCreate - Cant Modify

Aug 21, 2009

My prob is the following: My android application has the class TestActivity (entrypoint) -my app uses "library.jar" wich contains J2ME classes, used as library -library.jar also includes "UIActivity" [can spawn several dialogs] wich is called by a (j2me) class of library.jar -I only have the .class files of the j2me-lib stuff, so I cant modify them, but I can do so on Android-classes

so... the short form:

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

finally I get the error:

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

Do I have to use Services instead of Activities? But afaik I have to give a reference of an activity to spawn dialogs.

View 3 Replies View Related

Android :: Using OnCreate DrawableState

Nov 16, 2010

Leaving aside the lamentable wording of the documentation for this method, it's not really acting as I hoped for an ImageView. I call toggle() from the onClick method of the view but the view system does not redraw my drawable with the checked state. However, if I initialize CHECKED_STATE_SET with android.R.attr.state_checked then the view is draw with the checked state.

So apparently my call to setImageState is not updating the state of the ImageView. The documentation for setImageState is totally blank in the case of an ImageView. What does this mean?

Here's my code:................................

View 6 Replies View Related

Android :: Can You Explain OnCreate And Bundles?

May 22, 2010

I have been looking it up and I just cant seem to wrap myself around the onCreate and Bundles. I understand that the onCreate is called when the program starts but its how the Bundles get passed around and how they are pertinent. Can anyone try to put this into plain english because I cant seem to find it well described.

View 1 Replies View Related

Android :: OnCreate And Orientation Change

Apr 28, 2010

I have an activity that checks stuffs online when it's created (is the GPS on and if not it asks if the user wants to turn it on).

The problem I'm having is that it is also doing it everytime I change the orientation of the screen.

I've read some comments on onConfigurationChanged() but is there a better way to be sure I'm checking the GPS only when the activity is first created?

View 4 Replies View Related

Android :: Can't Put ProgressDialog In OnClick() Other Than OnCreate()?

Jul 30, 2010

I try to call inside onCreate() it is ok but not onClick(). How to make it work?

View 3 Replies View Related

Android :: OutOfMemory Exception In OnCreate

Oct 2, 2010

I'm having a hard time resolving a crash report. It's an OutOfMemory exception that occurs during the setContentView in the onCreate of my main activity.

I just want to be sure I understood Android LifeCycle well :

1) The onCreate of my main activity is called once and only once during the life time of my application ? Is that correct ?

2) Just like for the big bang, before the oncreate of my activity, nothing exists for that activity, so memory consumption is zero, no objects exists right ?

So what can cause that sometimes, with random framework and devices, I get an OOM exception ? I mean if say my background image is causing this, it should blow up everytime, on every device, shouldn't it ? I mean the result should be reliable.

The background image is a standard jpg : 360*480 weighing 37kb, nothing fancy really :s

The crash report below :

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

View 8 Replies View Related







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