I have to start an activity from adb shell using am start command. But in the activity it is taking an object of java.io.Serializable type as extra value in the intent. I know the class name of that object and I can create that object but i am not sure how can i pass this object in am start command as I am unable to find the flag for that. through Intent object its very simple with the method intent.putExtra(String name, Serializable value) which takes name of the object and Serializable object but through shell I am not sure. Is it possible?
Asked
Active
Viewed 4,097 times
1 Answers
3
One option could be to create an instance of the object and convert it to it's Base64 string representation using the method described here. Then you can pass that string as an extra using the -e
flag in the am start
command and convert it back to a Java object in the app.
Another option is to convert the object to a JSON string using Google's GSON. As above, just pass the JSON string as a parameter using -e
and deserialize in the app; however you will need to be careful and escape the quotes in the string as necessary.
-
Well at the mentioned link they are encoding and then decoding the string at retrieval time. But the problem is I don't have the source code of the app. So, I can't decode it in the app. – shahzad Mar 28 '14 at 09:13
-
1In your scenario, the best way would be to write a smaller launcher app that can use the data passed in by the method I described above that launches the other app's activity using `intent.putExtra()` as you described in the question. Unfortunately, I don't believe there is a way to directly synthesize a Serializable object from the command line. – Carlo B. Mar 31 '14 at 21:18