Android :: ListView SetAdapter In OnCreate - GetChildCount Is Zero In OnStart?
Oct 7, 2009
I want to display a ListView with checkboxes, and I want some of the checkboxes pre-selected. The ListView has setAdapter called during onCreate, and the list information appears when the screen is drawn. However, when I attempt to set certain list items as checked, my ListView reports getChildCount() = 0.
My SharedPreferences contains a list of sounds that have been previously selected, as a comma delimited string of list indices. Because the list appears to have no children in onStart, my attempts to set items as checked fails.
On the good side, once the list is rendered, I can select entries and hit Back, and my selection is stored to SharedPreferences correctly.
How can I load my previous selection into the list? Should I be using something else here?
In the spirit of open source. here's my code:
CODE:.................................
View 12 Replies
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
Dec 14, 2009
I got my hands on Android which is really fun. But at some point I don't seem to understand the concept. I've got a Main class which reads like this:
CODE:....
In the onCreate(...) I set the layout to setContentView(R.layout.main); and add an OnTouchEvent Listener to the sole View in main.xml: myView.setOnTouchListener(new OnTouchListener() {@Override public boolean onTouch(View v, MotionEvent event){...
As you can see I also implemented a SensorEventListener which is used if required. All works fine so far.
But my problem is this (at this point my misunderstanding kicks in): whenever I rotate the device the onCreate(), onStart() etc. methods are called, causing my app to act as if it just started. Furthermore, I feel unable to implement an onSizeChanged(int w, int h, int oldw, int oldh) { ... } Listener.
Can anyone please explain where my error in reasoning is? I am working on a tiny app which is more or less done, except for the just mentioned bug(s). Maybe I got it all wrong but it does what it is supposed to do (i.e. sending touch positions and accelerometer data over the network via UDP).
View 14 Replies
View Related
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
Jun 2, 2009
Im using a base adapter for binding a data from array to listview....the listview has a checkbox with it...i wanted to create a menu to select all or deselect all view inside that list...but the getchildCount method is behaving abnormally..i m not able to get the correct child count...
CODE:................
View 12 Replies
View Related
Jun 9, 2010
I have an xml layout file which contains a few widgets including a Spinner
I want to display a list of strings in the spinner, the list is generated at runtime as a result of a function so it can not be in arrays.xml.
I tried doing:
CODE:...........
But this crashes my application.
View 1 Replies
View Related
Apr 14, 2010
I'm trying to start a floating activity from onStart to retrieve some info from the user right when the initial activity begins.
I have the following:
CODE:............
And callProfileDialog() is just:
CODE:..........
ProfileDialog.class returns a String from an input box. If the result returned is RESULT_CANCELED then I restart the activity.
The problem I'm having is that when the program starts, the screen is just black. If I hit the Back button a RESULT_CANCELED is returned then the initial activity shows as well as the floating activity (since it recalled itself when it got a RESULT_CANCELED). Why can't I get the activities show by calling ProfileDialog.class from onStart()? I got the same result when I called it at the end of onCreate() which is way I switch over to use onStart().
I have also tried the following:
CODE:.........
But this doesn't work either. It all works fine once I hit the back button but without doing that, it's all black.
View 3 Replies
View Related
Oct 5, 2010
In the Android Application Fundamentals it says that after the call to the onStart()-method of the activity lifecycle either the callback method Resume() or onStop() is called. In case of an "normal" Start of an activity the system calls onCreate(), onStart(), onResume().But does somebody know an example where onStart() - onStop() are executed one after another?
View 2 Replies
View Related
Jul 25, 2009
I have a service that needs to hold a persistent TCP connection, think IM. I'm reluctant to use setForeground() - the service being down temporarily isn't that big a deal, and I am assume I can trust that I'll be run again once memory is available, correct? The problem here is this. The service was started via startService() before being killed. However, when it is restarted, only onCreate() is executed. This makes it hard to continue, because starting work onCreate() means I can't even bind to the service (to say query it's status) without it doing so. Is this a bug or per design? What is the status of the service after it is being restarted? Is it consider "started" by the system, i.e. waiting for a call to stopService()?
View 2 Replies
View Related
Mar 7, 2010
In the 1.6 API, is there a way to ensure that the onStart() method of a Service is called after the service is killed due to memory pressure?
View 4 Replies
View Related
Mar 7, 2010
In the 1.6 API, is there a way to ensure that the onStart() method of a Service is called after the service is killed due to memory pressure? From the logs, it seems that the "process" that the service belongs to is restarted, but the service itself is not. I have placed a Log.d() call in the onStart() method, and this is not reached.
View 1 Replies
View Related
Mar 31, 2009
I have noticed that if my background service crashes the system will automatically restart the service after 5 seconds. This is great, but I have noticed that only the onCreate method gets called and not the onStart method. Does this mean the service is properly restarted or do I need to do something special in the onCreate method to make sure it is? I did have my initialisation logic in the onCreate method and my starting service logic in the onStart method but it looks like it will all have to be in the onCreate method.
View 2 Replies
View Related
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
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
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
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
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
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
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
Nov 6, 2009
CODE:.......
Phone was an HTC My Touch. I got the prompt to choose what activity, browser or youtube, chose youtube.
View 2 Replies
View Related
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?
View 2 Replies
View Related
Jul 30, 2010
I am making twitter application in which i open browser for user authentication and i pass call_back URL when launching authentication browser.
Problem is after authenticating it is calling again oncreate of TWitterShare class instead calling onNewIntent method, why is that ? my another class working fine i am unable to find difference any idea by looking at the following ocde why it is calling oncreate again ?
CODE:...................
View 2 Replies
View Related
Aug 23, 2010
I got this class, and nothing inside the onCreate is happening? Does it not automatically get called upon initialization?
Code is below.
CODE:......................
Doing this results in a "application has stopped unexpectedly. Please try again". If I initialize the string to some set of characters instead of null, it'll just stay that way. Should it not do what is inside the onCreate() and make that change?
View 1 Replies
View Related
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
Aug 17, 2010
What is the lifetime of a ContentProvider in Android? After onCreate() is invoked, will the ContentProvider persist unconditionally for the lifetime of the process?
My ContentProvider manages a list of records, but only 1 is designated "active" and will be accessed by different applications a lot. I was wondering if it's safe to cache the index of this active record in memory as a member of my ContentProvider to speed up lookup.
View 1 Replies
View Related
Jul 14, 2010
Why if I start the MPlayer from the onCreate it doesn't start?
I tried also from onStart(), but the only working way was from onTouch or on key press.
Any idea how to start it without any additional user input needed?
View 1 Replies
View Related
Aug 10, 2010
I have a main activity and a sub activity.The main activity starts the sub activity using startActivity, and passes an object in the intent.The sub activity reads the object out of the intent in its onCreate action.The sub activity updates the object, then returns to the main activity using startActivity, again passing the updated object back.However, the main activities onCreate function is not called, so the code it contains to read the passed object does not run.Further investigation indicated that the main activity onPause event is firing, i.e. it is only paused when the sub activity runs, so when the sub activity starts the main activity again, it just on Resumes.Does anyone know if there would be any disadvantages if I moved my data restore/store activities to the onResume and onPause events?I'm not using the onCreate saved Instance State, should I be?
View 4 Replies
View Related
Jun 30, 2010
when writing a ContentProvider I have to implement the onCreate()-method, in which I establish my database connection. But to write the changes I made to the database I have to close the database on some point. Does something like a onDestroy()-method exist for ContentProviders or is there some intent I have to listen to, which is fired before killing my process?
View 5 Replies
View Related
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
Sep 15, 2010
I have a TabActivity with 3 tabs, each tab started an activity and I realise when a tab is clicked onResume is call. If I have onCreate, when app start it will launch onCreate and then onResume immediately.So, I can just get ride of onCreate in this case?
View 2 Replies
View Related