Android: How to fork a new process - android

I want to run two processes in the same DalvikVM. This means that I want to run a first app and then that this app starts the second app. And I want that this two apps are then running in the same DalvikVM. I think it is possible if the first app forks an process for the second app. But I´m not sure how can I do that.
Thanks

I want to run two processes in the same DalvikVM.
By definition, that is impossible.
This means that I want to run a first app and then that this app starts the second app. And I want that this two apps are then running in the same DalvikVM.
By definition, that is impossible.
I think it is possible if the first app forks an process for the second app.
No.

I very much doubt what you actually want to do is go digging into the specifics of processes (if you do I would question why). In any case, Android deliberately makes it very difficult for you to go near processes as the platform provides sufficient mechanisms to achieve virtually any functional flow without needing to.
I suspect what you actually mean is you need to start a new Android task (has it's own back stack, functionally operates like a separate application).
Have a read of the Tasks and Back Stack document from the dev guide, particularly the section on tasks. What you probably want to look at is starting your new activity using the FLAG_ACTIVITY_NEW_TASK flag in the Intent.

Related

Alternative to saving state of activity : ram check [Android]

So theoretically, if I had a webview that loaded multiple pages in one session AND in one activity, if I was unable to save the state of that activity like I normally would via Bundle onSavedInstanceState, is there a way to prompt the app to check for available ram usage/memory?
I'm looking at a way to maintain activity state with webviews using the "Do not keep activities" turned on via developer options. Basically, when the app launches a new activity from an activity with a webview, on return, the pages that the user progress would have vanished because this would be a new activity instance.
Like, I'm looking for a possibility to check available ram usage via code to prompt the app to quit should there not be enough memory to use.
Generally, this should happen as Android will take the least frequent activity on the stack and destroy that to make more ram space available, so this is more of a theoretical question than a practical one.
Actually, your theoretic exercise is pointless. If Android needs memory, it just kills off background processes. It does not selectively destroy Activitys within an application. The documentation alludes to this possibility, but in reality this is never done.
The developer option "Do not keep activities" is something that always breaks complex applications when it is turned on, and it is something that can be used for troubleshooting and testing certain behaviour, however it doesn't really mimic the actual behaviour of the Android framework and it breaks a lot of code. For example, try using startActivityForResult() with that option enabled and see for far you get!

Iterate all activities in one android app recursively

If we look at one activity as a graph node, transition/calling from one activity to another as a graph edge, one android app can be conceptually converted into a graph. I am trying to see if there is any way to create such a graph starting from the first page/activity of an app.
Let us say we can use android UI test automator to help if needed.
I am trying to see if there is any way to create such a graph starting from the first page/activity of an app.
It would be exceptionally difficult.
I am assuming that you are trying to hack... er, I mean, "analyze"... somebody else's app. In that case:
You have no idea how many activities there are, unless you are reverse-engineering the APK. And even then, you have no idea how those activities will be used (e.g., legacy app that is putting activities in tabs and not using them as an ordinary activity).
You have no way to know what triggers the activities to appear. For example, a certain activity might only appear via an "Easter egg"-style bizarre set of inputs. Some might be triggered by things outside the app itself, like a Notification or a third-party invocation of ACTION_VIEW for some MIME type the app supports. And some of the triggers may be dependent upon other inputs (e.g., a disabled action bar item that becomes enabled only if you have set up an account elsewhere in the app).
With full source code, you could do static analysis to find all startActivity() and startActivityForResult() calls, and for simple variations you might be able to divine which activity starts which. Even that could get tricky in some cases, for complex Intent construction.

How to save&load a snapshot of an Android app state?

Before reading this, note that I'm not talking about capturing the screen.
Motivation
Many times, in order to test apps, we need to go over many activities (including a loading/splash screen) till we reach the one we've just updated in order to test it out.
I want to reduce this time , by capturing the exact state of the app (memory,preferences,activities stack,...) in order to go there again.
Another example : The QA team could show me in which case a bug occurs, without having to show me the whole process till they got there (since it might not be reproducible) and then I could run the app, and know exactly where the exception was thrown and go there directly via the DDMS's logs .
Another example: We work on a game, and the QA team have tested the game for hours and reached a certain stage, and would like to save the current state of the app in order to test it from this point and make multiple tests on it, instead of running the app from the beginning each time , wait for it to load and also finish all of the stages till they reach this stage.
I think there are other scenarios where such a thing could be useful.
The problem
Such a thing is probably possible in the VM world (for example virualBox) , and it's probably possible for android emulators (at least according to this post , but they also say it's "finicky" , not sure what that means in this context) , but not for devices.
The above example, though they might work, they work for the entire OS and not for a specific app, so even if I choose to use them, it takes a long time to use (plus I need to use an emulator which is usually much slower than any device) .
I'm pretty sure that the current API doesn't support such a thing (and it's probably a good thing, for security reasons).
The question
Is it possible to capture&load entire app state by using ROOT ? Maybe by being a system app too?
Maybe there is already an app for this task?
Since it's very usual that an application saves its whole state in SharedPreferences and persistence in DB, in most apps you can backup and restore data and state using adb backup and adb restore, respectively:
Backup:
adb backup -f app.ab com.company.app
Restore:
adb restore app.ab
PS: This feature was introduced in ICS, and it's not required to be root.
More information in this tutorial.

How to get a notification in Android when a built-in app finishes loading

I am trying to create a benchmarking app that launches a few apps and measures the load time. Starting a timer and launching an app (via intents) is the easy part. And, if I have source to the child app, I can either have it record the time and pass that back, or I can just have it kill itself completely at some point. But, how do I know when stock apps have finished loading? Or, how can I make them close automatically so that mine is brought to the foreground again to stop the timer? I know the source for stock apps is public, but I don't think it's practical for me to try to modify it. Or is it? I can't tie my benchmarking app to a specific version of Android.
Specifically, I'm interested in measuring load times for the browser, youtube, and mail.
I've looked at using the ActivityManager to get info about running apps, but I think in that case I would have to poll in the background, and I've read that ActivityManager info is not necessarily always up-to-date, anyway.
Any suggestions would be very much appreciated.
I decided to just modify the source and build a version of my app for each version of Android/processor. I won't have to target each device specifically, just processor families (Atom/armV7/etc.)
Getting and compiling Android source is easy
Building a custom version of a stock AOSP app is also not that bad
From there, it's just a matter of using intents to invoke activities and pass information.

How to combine two applications into one

Following my previous question, I found out that using BroadcastReceiver to launch my service, the service launches on startup and it doesn't show on task killer.
now my question is, how I add this application (or package) to my main application, so it will be installed as two applications.
I tried to add it as a library, but then the service is attached to the main app, and it can be killed with task killer.
Your question confuses me. Perhaps it is because on the Android, the words 'activity', 'application', 'service' etc take on different meanings from what they would be on another platform. Perhaps you can describe better e.g.
What icons do you want to see on your app launcher?
What entries do you want to see in your app manager > installed apps?
another thing i didn't understand is "how to add this app/pkg to your main application, so that it will be installed as two apps". If you add a package to your main application, then there will only be one application.

Categories

Resources