I'm having some problem here with android + java + cloud. My onCLick event is working only one time
The event only work again when i go back to the last screen and enter again in the screen that i made searchs in the cloud...
I think you are only allowed to call setContentView() once. Since you are doing it in your click listener that might be why it is failing after the first time.
Edit: What does it do when it fails? Force close? nothing? something unexpected?
Related
I'm new to android development and working these days on my first app.
In my activity, in the onCreate function I make 2 function calls , each of the 2 functions has different OnClickListener for different buttons.
Everything works fine , my question is why?
I mean how does it possible that both of the listeners functions "work" on the same time does the app runs in a parallel way? In my head I thought that once the app reach an OnclickListener it will just stop and wait for a buttonClick event but I can see that I can click on button1 and something happens and then I click on Button2 and something else happens (as it should).
I just want an explaination, in general, about the way (flow) the app work/ handles functions of listeners and click events.
Thank you,
Noam
I totally understand what you mean.
button.setOnClickListener(this) means this button just tells the activity that it has a click event. The app won't pause or wait until the button event is executed.
when different widget is clicked, it's own click event will be executed.
My app currently has only one Form, which listens to the accelerometer sensor. In my start() method, I turn the listener on, and in the stop() method, I turn it off. I have verified that the listener turns off when I hit the Android's home button, but when I hit the back button, the application exits and the Android returns to the home screen, but the listener keeps going, which means the stop() method never got called. Is it my responsibility to handle the back button with code to call the stop() method? Or is this a bug in CodenameOne's framework? It seems to me that when the back button returns the user to the home screen, it should call stop() for me.
I am not sure about all the details of your issue, however you can resolve it by calling the setBackCommand on that one form.
yourForm.setBackCommand(
new Command("closing the sensor listener"){
#Override
public void actionPerformed(ActionEvent ev){
// your code to close the listener
}
}
);
I don't know about CodenameOne framework, but When app is visible and you press back button it calls all four methods in following order
1)onBackPressed()
2)onPause()
3)onStop()
4)onDestroy()
and when you press home button it calls only
1)onPause()
2)onStop()
methods
so, when you press back button onStop must be called.
You please put source code so that people can understand your problem clearly.
I don't know about CodenameOne framework, but I know the Android SDK.
Activity.onBackPressed() should be invoked when you use the back button. Just because your Activity is no longer visible does not mean it has been reaped, and this might explain why Activity.stop() is not invoked (immediately).
Depending upon your use case, Activity.onPause() might also work better.
HTH. Good luck w/your project.
This has been fixed. I've verified it, and it works correctly now.
I have a simple Apache Flex view based application that runs on Android as follow:
<f:MyView xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/sparks"
activate="activateHandler(event)"
deactivate="deactivateHandler(event)"/>
I expect the activateHandler() should execute only once when the view is activated, however after I pop and then push the same view back the number of activateHandler() execution increased by how many times I did the pop and push operation. Why would this happen and how to force it to operate as expected (i.e only once)?
Expanding on #JileniBouguima's answer, changing activate to creationComplete will resolve this because of how those events work. Your expectation that activateHandler() executes only once is a little off; according to the Activate event documentation, activate fires
every time your application gains operating system focus and becomes active.
By contrast, creationComplete fires once per object, once the component is created.
I am not sure what code exactly is written in the handlers activateHandler and deactivateHandler but in Flex this is a standard practice to remove event listener if you do not need it any more. I am assuming that whenever you pop and push the same view it is adding and removing the listener. I can help you more if you share the handlers code.
Change activate to creationComplete.
I am trying to use the Eclipse debugger to debug my Android application, but it doesn't seem to be working. I have a callback in my MasterActivity.java file for onOptionsItemSelected, and I set a breakpoint in this method at a point that I know is being hit. I then right click my application, and go to Debug As -> Android Application. When I click the button in the ActionBar that triggers this callback and should start the debugging process, my program just continues like my breakpoint is not there. I must be missing something basic here, but I'm not sure what.
Simon's suggestion to add a Log message is a good start to ensure that the callback is being called, unless there is already some other evidence unique to the callback that it is being triggered. We can only guess as you haven't included any code, and nothing wastes time like a programmer assuming they are correct, myself included ;-)
However, try adding a call to waitForDebugger() just prior to the line with the breakpoint active.
A good way to check if an item, in this case a menu item I guess, is to use the method Log.d(String tag, String message). So in your onOptionsItemSelected event handler, you can add e.g Log.d("Debug", "Options item is selected"). It isn't necessary to use Debug As, Run As will work too. The log message will be displayed in blue in the LogCat in Eclipse.
I am trying out a simple game type app where i draw co-ordinates on the screen where the user has clicked.
The problem is , the app gives ANR if i dont click for some time
My code is listed here
Your code is a little bit confusing (there is probably a lot of things to clean).
Anyway I think the problem is the following : after a some times of inactivity the SurfaceViewTest.onPause() is called by the Android OS. This method call renderView.pause() where you have an infinite loop
while(true){...}
and so the pause() method never ends.
If you write :
while(renderThread.isAlive()){...}
it will solve the issue you are describing.