How to debug field in Android Studio - android

I'm using Android Studio to debug class field, the things I want to know is:
who and when changed the variable. But it seems that it doesn't work like a regular break point, whenever the field gets changed my application just stops and there is not such option as Step Over or Resume Program in debug window. My tool bar looks unusable:
So, as you can see from the Overhead the field was hit once, and my application stopped afterwards. Also it doesn't show who changed a variable, or how it was changed(via setter or from inside class). How can I make it work?

Both "Add watchpoint" and adding breakpoints every time value is updated almost did the trick.Actually, None of the breakpoints were triggered at all, but it led me to conclusion that the application was not using the correct object at all, and yes, the hashcodes of used object and the object that application
should have used were different, should be more carefull with singleton :)

Related

how to get and store android app startup launching time

How to get value of application launching time,
from available solution on android log is printed like this I/ActivityTaskManager: Displayed com.android.demo.MainActivity: +1s751ms
Any solution to store this value in variable to use further
I don't think is possible to store that value somehow outside Android Studio because this things and others involving performance issues are viewable only inside SDK. For further references see this:
https://developer.android.com/topic/performance/vitals/launch-time

How to debug code in android studio with all the classes which we have used in the project?

I have a simple question related to the How Debug code in android studio, suppose I have two classes in my application fist one is MainActivity.java and second one is SunshineSyncAdapter.java that contain method initializeSyncAdapter().
I am accessing SunshineSyncAdapter class that contains method initializeSyncAdapter() in my MainActivity.java class. My question is that I wanted, my debugger/cursor in SunshineSyncAdapter.java class so that I can get what is happening their, debugger is not redirect to the second class code is like this in MainActivty.java class.
SunshineSyncAdapter.initializeSyncAdapter(this);
First decide values of which variables matter to you. Find those lines in the code in studio and then put breakpoint there . Now if your application is already running , find attach debugger option in menu at the top and attach debugger to the process you want and you can use watch , evaluate expression etc. If you run application in debug mode then also you will be able to debug the application. Use step over , step into , step out etc as usual which are at bottom left in android studio.
You can debug your code same as debugging in eclipse.
You need to add break points where you want to break code and then
1.Launch project in debugging mode.
2.If you want to debug on run time :: attach debugger to running process by click on button left to settings.

What should i do, if debug is not working correctly (Eclipse IDE, Android SDK)?

I don't know if this question is suitable for this site or not, but I think this place is better for this kind of question than stackoverflow.
I'm developing an Android application using Eclipse. I always debug and log when I encounter a complex problem/bug when developing apps.
However, this is the first time I encountered a situation where debug and log seem not working correctly. This is what happened:
When I run my apps (using log) : The getView method in my adapter is not called, i know this by using log.
When I debug it step by step : The getView method in my adapter is called, however it gives me the NPE (Null Pointer Exception).
When I debug it, but not step by step : Same like when i run my apps, the program never entered the getView method.
Note : The 3rd means that I set some breakpoints, then I debug what I need to debug (not step by step), then I skip to the next breakpoint, while the 2nd means I debug the apps step by step, not skipping anything.
I have tried to solve this bug for more than 20 hours, but I still can't get things working correctly.
Have you encountered the same problem like mine, while running and debugging a program, or even different method of debugging give you a different result?
What should I do now?
are you working with threads ? if yes please check code your for synchronization blocks. These kind of problems happens when you miss some code blocks for synchronization. Always behavior will be strange.

Issue when calling ffmpeg.c twice that makes the app crashes?

I'm trying to call ffmpeg.c to trim a video based on this code 'video-trimmer'. So when I try to run the activity (that loads and uses the native lib) the first time I click trin it works and I could trim the video but when I try to run it again it crashes (and it only work with the application restarts).
So I spend three days looking for a solution for this issue, most of the answers says the issue with the static variables in ffmpeg.c and creating a lib that loads and unload the class fixes the issue (answer1, answer2). So I tried to apply the solution that is based on the answers and this github repo on the video-trimmer project but all my attempts failed.
Is there any one knows about a fork of the 'video-trimmer' project that fixes the issue?. or can anybody provide step by step answer of how to implement the solution in the 'video-trimmer' project (because I tried to follow all the solution on the web and apply them in that project but with no luck).
the problem seems to be with the initialized values (some variables are declared as global static vars, presumably for ease of access but breaks OOP principles and causes us problems like you're facing), however, there are a few ways round this that I can think of:
write a quick function to manually set the static vars back to their correct init values (quick and dirty but works). A list of methods which should not be allowed to fire off as and when they please follows:
avcodec_register_all(), avdevice_register_all(), av_register_all()
avcodec_find_encoder(), avcodec_find_decoder(), av_find_stream_info()
avcodec_open(), avcodec_close()
these could be wrapped in a boolean controlled method for example so that if they have run previously they cannot run again.
another way to control things is to manually force the variable values (by use of a class or struct to control the ffmpeg global vars) that are being re-initialised on subsequent runs, for example on running the method which currently causes the code to fail, the first step could be to manually set the variables back to their default settings so that they run correctly as at the moment I suspect you have data remaining resident between iterations, and thats what is causing problems.
you could utilse mutexes to ensure that the aforementioned methods behave more responsibly when used with threads.
Addendum:
also (at the C level) use libffmpeginvoke in preference to libffmpeg if you are going to invoke main() multiple times
forcibly invoke Garbage Collection (yep this is another 'ugly' fix) on the call to load the ffmpeg lib, which would then clean things up allowing you to call another instance
Let me know if you need something more in-depth: I can try making a test framework to replicate your problems and see where I get, although that needs access to my home PC as when I am at work I have no Android SDK.
Help us help you, please provide your implemented code or a part of it. Also Crash Log will be helpful.
Hint: Initialise ffmpeg object/thread.
Then use a call back interface. Once the VideoTrimmer gets over, give a callback.
In that callback call the destroy/kill of the ffmpeg object/thread.
May be this link can help you.
I have recently used the "android-ffmpeg-java" project from github, this is a working library, I can guarantee. You just have to implement a wrapper (test application) which will do the work.
Check this link for Source : android-ffmpeg-java
Check this link for example : android-ffmpeg-cmdline. See if you can solve on with this.
I am not sure if this will help, but C files typically have a header where you can use
ifndef
Please see the following:
http://www.cprogramming.com/reference/preprocessor/ifndef.html
Use that syntax to sandwhich the declaration in the associated .h file to ensure multiple imports don't cause a crash in the importing code.
Good Luck!
Edit: Ok, looks like that would mean recompiling ffmpeg to the .so file. You should just try to verify that it has a mechanism as described above in the codebase and try to confirm it isn't somehow being loaded twice.
While somewhat crude, a potential workaround could be to utilize/link to ffmpeg from a Service (you had better be doing that anyway) which is declared in the manifest to run in its own process rather than that of client Activities. Then have that process terminate itself - calling native exit() if needed - when the task is completely finished. Android won't particularly like that happening - it's not good practice - but you can probably make it work.
Re-engineering the library to be able to reset itself to a fresh state (or even make it entirely contextual) would be better, but for a huge legacy codebase may prove to be a large project.

Get rid of all user data of Android application after bigger update

I completely revamped an app. Tested it for a while on my device and emulator. The app worked fine. However when I updated the app through the Android market, my users experienced crashes.
Since there is no way to properly debug this procedure I asume the crash is caused by old data which is not being removed from the device (probably from the onsavedstate bundle?!).
Is there a way to do a "clean/total" reinstall without having the user to do it manually?
Best Regards
Johe
When the variable that's giving you trouble is overwritten with the proper type on the next OnPause, the class cast problem should be gone. You could reserve one variable to hold a version number and if the one you retrieve from OnResume is older you skip the other saved values and use the defaults.

Categories

Resources