Delphi TerminateThread equivalent for Android - android

I have been discussing a problem on the Indy forums related to a thread that is not terminating correctly under Android. They have suggested that there may be an underlying problem with TThread for ARC.
Because this problem is holding up the release of a product a work around would be to simply forcibly terminate the thread. I know this is not nice but in this case I cant think of a side effect from doing so. Its wrong but its better than a deadlocked app.
Is there a way to forcibly terminate a thread under Android like TerminateThread does under windows?
Martin

Well, I don't think harshly terminating threads is advisable, but that notwithstanding, from what I read of the System unit, you should be able to use this:
uses Posix.Pthread;
...
pthread_detach(pthread_t(TheThreadObject.ThreadID));
Untested, mind.

Related

How to see the problem raise by user which cannot simulate from our side

My customer raise a problem about our app which is the app is getting slower when using for long time, but our side cannot simulate the problem as we are not in their real working environment, we are not able to solve the problem before knowing the bug. anyone can help?
If it´s a issue that raises "by the passing of time", you should look for any task you might be running and repeating itself.
You should check the different types of functionalities you use.
For example, if your app it´s using a local database:
Look for unclosed cursors.
I/O work
If your are using animations:
Look for skipped frames
Complex view hierarchies
If using background tasks or threading:
I/O work
Unfinished threads
Increasing thread number
If using networking and Webservices:
Problems with your server database
Connection issues
Proxys
...
You could also use something like Firebase + Crashlytics to see if theres any warning raises but gets silently disposed.
Giving some more info about your app and what it does could be useful for elaborating more accurate solution.
A common source of slowing down apps is memory leaks.
on iOS what you can do is to activate Memory management flags on your target and keep a watch on the logs, you can also use Xcode Memory Graph and instruments leak tools to detect leaks.
on Android you can use tools like LeakCanary to be notified when leaks happens.
Once you have a leak detected you can inspect your code to identify the source and better manage memory.
#axierjhtjz mention lots of good starting points.
Does it occur on both iOS and Android, specific devices, vendors?
If it is mainly on a single platform (Android/iOS), on different devices and the main complaint is slowness over time, I would suspect the following:
Memory leak (maybe UI, fragments)
Data persistent data incremental over time or/and more IO operation over time.
If you unable to debug the problem on the customer site, I would suggest to add a remote real time monitoring capabilities over relevant parameters and logs.
A good tool we used in the past was TestFairy. maybe they have a free trial

What kind of multi-threading conflicts/deadlocks can occur in Android?

The known danger of multi-threading in android is accessing UI from another thread. But what other types of conflicts can occur in Android. Is it possible to have a deadlock using looper and handler? If so, how could this occur? Frankly I have not experienced deadlocks in Android, but I keep getting this question from folks, and don't really know how to answer it.
Bugs related to multithreading such as deadlocks and race conditions are no different on Android than other platforms. Giving you an exhaustive list of these problems and possible solutions is beyond the scope of this web site due to the necessary background you need to acquire.
The following URLs might answer your question:
http://www.techrepublic.com/article/avoid-these-java-threading-gotchas/
https://tudorturcu.wordpress.com/2013/05/15/some-multi-threading-gotchas/

How to communicate via Socket in Android 4.0.3

I already have a socket communication interface which works fine in 2.3 version, but It doesn't work on 4.0.3, I've heard that it's not possible to make this kind of communication in the same thread as UI in this version so, I'm beginner in android and didn't found any example on this type of communication in 4.0.3 version, do you have some example or can tell me how to do it ?
Thanks in advance
The easiest way to do work on a different thread is to use AsyncTask. Be aware of the fact that your AsyncTask will break if the context gets destroyed, for example if the screen rotates. You will need to handle such events, as well.
You could read this SO question and start from there.
Here's a quote from the AsyncTask docs:
AsyncTasks should ideally be used for short operations (a few seconds at the most.) If you need to keep threads running for long periods of time, it is highly recommended you use the various APIs provided by the java.util.concurrent pacakge such as Executor, ThreadPoolExecutor and FutureTask.
when you are using ICS or JB, you are restricted from opening network connections from within your main activity. you will get an opaque error message regarding network permissions. this is true from ICS onwards (so froyo and GB would not complain).
i cant repost my answer to another quite similar StackOverflow question here (it is considered spamming by moderators), but you can CHECK IT OUT HERE.
i posted a functional send and receive socket connector client using asynctask there.

Android startActivity - What is happening

What is happening under the hood? somehow this is passed down to the OS, and someshow the OS will find the right activity / activities, and launch it? Is there a service / lib running in Android handling this? I am trying to modified the OS to override the logic of startActivity across the board, is this possible?
Thanks.
I would take a look at the Android source! Whenever I'm developing and I run into an issue I read through the source to discover what is happening under the hood; it's quite interesting! It's an insight into what's actually going on, and also very good guidelines for documentation and code formatting!
http://source.android.com/source/downloading.html
A good starting point might be ActivityManagerService
Basically, when an app is first launched, startProcessLocked() in ActivityManagerService creates a new ProcessRecord (if necessary) and then calls Process.start(), which in turns builds the arguments for zygote and sends to zygote's socket using zygoteSendArgsAndGetResult(). Of course there's more to it than that, for example if an app shares a uid, is isolated, etc. But that gives you the basic process.
Looking over the source is indeed a good way to understand what's going on. However, unless you're planning on modifying it, don't bother downloading AOSP, just use GrepCode. Easier to browse, search and everything is hyperlinked so it's easy to follow through to classes, find usages, derived methods, etc. If you download AOSP, you'll be stuck with grep, ack-grep if you're lucky and a text editor. Also, you'll only have the one version you picked to checkout. GrepCode has the code for almost every version since 1.5.
The linked text above will take you to the relevant source at GrepCode. Try it out! The only downside is that GrepCode doesn't include the native C++ layer.

How to measure Phonegap UI performance?

I want to make performance improvements to my Phonegap application, currently targeting Android, but I want to base my actions on some measureable evidence.
Are there any tools I can use to measure the performance of Phonegap UI (time from clicking to finishing the action) on device? And mainly to measure the improvement of these times after I do some performance tuning?
Yes, you can use Traceview - it's an excellent tool:
http://developer.android.com/guide/developing/debugging/debugging-tracing.html
I'm currently using this
and i strongly recommend it
https://github.com/GameMaker/PhoneGap-Performance-Test--PGPT-
JavaScript is GC based language. It means, it has unpredictable GC time which makes main thread stops. This makes UI struggles. On native implementation, you have control to use GC or not.
This wouldn't be a problem on Android. Android always had those struggling because of GC on Java. Considering this fact, most of Android users doesn't care about UX a lot. But on iOS, your HTML5 based app never be better experience than competitor's native app.
There are many workarounds for this GC time issue. Such as incremental-GC, realtime-GC and so on. But actually, there's no real solution. Because the primitive problem is you don't have control.
Regards
Rajeev

Categories

Resources