I'm new to android development.
I download a toy project and want to figure out the flow of this project.
Can I use debugging to figure out it and how?
Let me explain it more detail. Every android project starts from an "main" activity. I guess I find the "main" activity for the project and set a breakpoint at the onCreate method of this "main" activity. I expect to run this project from that breakpoint one step by step to figure out the flow. However it doesn't work since the debugging stop after finishing the onCreate method.
Start with AndroidManifest.xml file. Open it and look for an Activity with LAUNCHER category. Then open that Activity and go to onCreate(...) method. This is where your app starts. Inside the method, there is a call to setContentView(R.layout.some_layout). some_layout.xml in res/layout folder is UI for this Activity.
Each window you see in Android app is an Activity and each Activity has a layout file.
The "flow" of an android application is more like an asynchronous model than a sequential flow of action. There is a main application loop that processes external events (such as clicks on button) and callbacks related to the activity lifecycle (such as your onCreate method), and lot of other stuff.
Every event is put into the queue and processed asynchronously, so it's not easy to follow it. It's better to think about actions and reactions. In any case you can dig into the android source code and see what's running behind the scenes. Some hints about the model of android apps can be found here but any google search for "android ui thread queue" would lead to relevant info.
If you want to learn the flow of a typical android application, I would recommend you download the samples if you haven't already and add your own log statements. You could use the debugger too. Then start making small changes here and there to force different 'flows' of control, as you make guesses about what should happen and observe your logging statements and the app behavior to see what's going on.
The sample projects can be downloaded from the adt plugin in eclipse and come as ready-made projects. They are also a good way to learn because they are generally the 'best-practice' way of doing things.
Hope that helps! Good luck :)
Related
I would like to write an Espresso test that I can run on an application from outside that application. I don't have much experience with Android, but, as I understand it, a UI test is generally written and executed from inside the project of the application that it is supposed to test. For instance, according to the file explorer in Android Studio, the java files for a test application I was developing are stored in com.package.example.name, and the java files for the UI test are stored in com.package.example.name (androidTest).
I want to develop a UI test for an application (Application A) for which I do not have the project files. As I do not have the project for Application A, I cannot develop the test for Application A from inside that same project like I normally would. Thus, I have to somehow create and run it from outside.
My initial thought was to create a test application (Application B) from scratch and add a button to it that, when pressed, will open Application A. I would develop an Espresso test from inside Application B, have it press that button to launch Application A, and then have it follow other Espresso instructions I would develop by viewing the R.ids of Application A's UI elements through uiautomatorviewer.bat, included in the Android SDK tools.
At least to me, this seemed like it would work just fine in theory, so I went forward with the plan. However, when the button inside Application B is pressed by the UI test and Application A launches, the test cannot find an activity to continue testing on. No error is explicitly thrown; Logcat prints messages like "W/RootViewPicker﹕ No activity currently resumed - waiting: 2000ms for one to appear," repeatedly, where 2000ms increases as time goes on.
Historically, I have not had any problems when running Espresso tests across activity changes. I assume this issue has something to do with the fact that the activity being launched exists outside of the project where the Espresso test is based.
If anyone knows of a way to get an Espresso test to run successfully on an application when based in a project located outside of that application, I'd appreciate any advice you may be able to offer. I think I'm on the right track, but I don't know for sure. Thanks!
I'm experimenting with Simple widget application in Xamarin studio and would like to know how to debug it. Trying regular 'Run -> Start Debugging' (F5) produces
Application does not contain a launchable activity
As far as I understand ActivityAttribute.MainLauncher property is designed specifically for this purpose but there is no activity to apply it to in the example I'm playing with.
p.s.
Is there something similar to 'Attach to process' feature?
It seems that there is still no simple solution other than embedding your widget into a self created activity just for the debugging purposes. The last post from the Xamarin team I've found is here.
I've tried a few approaches with an empty activity and trying to trick the debugger - but failed.
Well i´m trying to create a application which should show some streams (udp/rtsp..) I found out that the vlc-player can handle most of it! So i decided to use the vlclib. On windows there is a vlclib which can be easily used. But how can i use the vlc-android project as a vlclib for my own app?
On the web i found another question:
Using libvlc on android with NDK
The answer links to this side:
https://bitbucket.org/tewilove/nyan.tv-jni/src
But the readme is really strange. It tells me only to compile it using the shell script... But this side referring to the nyan.tv-jni project tells me that i can use it simply as a wrapper in my code? http://blog.moenyan.net/?p=18
So now i´m really confused... Can anyone please help me shed some light on how to create my own app using the lib?
Thanks in advance.
I found a solution for my problem. I decided to build my application into the vlc application. I cloned the git-project from vlc and followed the instruction to build a ARM-CPU version. After the successful compilation I was able to merge my project into the vlc application.
Just change the package in the AndroidManifest.xml, change the declared classes from for example:
.GUI.Main to org.videolan.GUI.Main
Remember to do not register your Main as the starting activity. Just start your activity after finishing the onCreate() of the VLC-Main activity. Remember to call finish() in the onResume() of the VLC-Main activity. The onResume() will be called after your destroyed your own activity.
// OnCreate
VLC.Main.onCreate() -> startActivity(Intent) -> MyApplication.Main.onCreate()
// OnDestroy
MyApplication.Main.onDestroy() -> VLC.Main.onResume() -> VLC.Main.onDestroy()
/!\ Remember to credit the VLC-Team for the great base!
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.
Hello I am trying to build an app which will hold "other app's"
For example MY app will hold different apps of different ClIENTS.
Now i want to make it so that 1 client has the option to only download his part, BUT he still has to use MY main app. (in other words i don't want to reference to another APK, cause then he can start his app without using mine(i think))
And the download option should be at runtime, cause else he has to download everything in one go.
I have thought about using jar files as library files, but what i found so far is that you have to add them in Eclipse (else they are not found)
I also thought about building the app with the jar files in it, and then leave them out when i compile the app. Then my client can download those files afterwards. But i am guessing that will cause reference errors?
So the questions are;
Is it possible?
How to go about?
The main idea is that i don't want to make one HUGE app where as my client will only use his part of it.
Thanks in advance
It can be achieved in android, and some big platform apps could let the 3rd party developers to develop plugins for them. The main idea is try to create your own DexClassLoader to replace the default one, the custom DexClassLoader could load classes from apkfile.
Try to look through this article for details.
Same with this question.
It seems this is a difficult topic. I can only give you some point.
Since you don't want to make a huge app, then you have to build CLIENTs as separate APKs. But if you don't define CLIENT's activity as MAIN and DEFAULT in manifest, after install CLIENT app, user could not find CLIENT app from system menu (launcher). You can define a private intent name for CLIENT app's activity, this way, only your main app could start CLIENT app's activity.