Give me a little guidance:
as My Application is running with Broadcast Receiver and when ever my application in Background and any incoming event comes it triggers the my Application.
Now we want as We are listening or playing some video file or browsing on Android Phone
and with incoming event occur and my application launch(already running in Background),
If i will ignore the event , we want to go back previous running task (Like browsing, playing
video file application), How we can achieve?
Now I am using The store the running application package and Activity info before triggering the Event , and after finishing using this info we resuming the Activity and
It working fine but Only with Gallery Application Playing of Vedio file is not fine , It Crashes the Application and relaunch the Gallery App.
Please give me some Valuable points to make it up?
On calling finish, Previous application resume(Playing of Media file) but when next time
on getting broadcast intent and try to launch the Activity , The Activity is not launching
and application itself crashing.
After a long back I got solution of my problem and we need only use to this api
moveTaskToBack(true);
and automatically resumes the previous running task(like browser, media application or any thing)
Have you tried to start you activity by
startActivityForResult(Intent intent)
When you call finish() in the Activity you should return the the previous one, I am not sure if this will function over between Activity running in different applications. Give it a try :D
Related
Currently I am handling onTrimMethod(int level) in my app with ComponentCallbacks2.TRIM_MEMORY_COMPLETE and ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL. I get this callback easily with low end devices when my app is running in background and simultaneously I am playing games.
In that I put Runtime.getRuntime().exit(0); to kill the app in background only so that when user taps on app (running in background), app will restart from launcher activity. I don't know it kills the app or not but when I open the app, first it shows dialog with "Unfortunately, app has stopped" and app does not restarts.
If I start the activity from this method, it will launch the application and bring it to foreground without any user interaction.
I tried some other ways too to kill the app. They are System.exit(0); and android.os.Process.killProcess(android.os.Process.myPid()); but none of them are solving my problem.
So, what to write in onTrimMethod() or how to handle in other way so that when user opens the application (brings to foreground from background) it will start from the first activity?
i made a sample android app,which starts a started service by calling startService(serviceintent).
it works fine,but if i forceQuit my application from settings>app>downloaded>force_Quit.my service stops and even destroyed is not called.
i studied for 3-4 days and know about start_sticky in StartOnCommand method.i am able to achieve all aspects of service.
I want to know whatever i am achieving that service stops and doesnot restart automatically even if started as Start_Sticky is normal behaviour according to android.Can i make it restared if user force quit my application.
my manifest is correct i uses process tag also.
if i forceQuit my application from settings>app>downloaded>force_Quit.my service stops and even destroyed is not called.
Correct.
Can i make it restared if user force quit my application.
No. Nothing of your app will run again until something uses an explicit Intent to start one of your components. Usually, that means that the user taps on your icon in the home screen launcher, though there are other explicit-Intent scenarios (e.g., GCM message).
I have made a Mediaplayer (just play songs from SD card) and it is not a service but a single activity. by pressing the home button the player continues playing in the back ground.
now my problem is how to get back to the same instance of the activity by launching the application. mine starts a new activity while the previous instance of mediaplayer is still playing the song.
I have seen many similar questions but mostly was about the services specially in mediaplayer cases.
is it possible to set some flags onDestroy and check them again onCreate or somthing similar ?
thanks
mine starts a new activity while the previous instance of mediaplayer is still playing the song
Yes, this is a behavior, on start - new Activity has been created.
I have seen many similar questions but mostly was about the services
There is no way, run Player in Service in order to bind new created Activity with the Player
Try using the launch mode - single instance, for your activity.
android:launchMode=[ "singleInstance"]
in your Media Player activity in Android Manifest.xml file. It might work.
If you press HOME to put the application in the background, and then launching the application creates a new Activity, you are probably seeing this long-standing nasty Android bug: https://stackoverflow.com/a/16447508/769265
To check if you are seeing this bug, just force close your application, then launch from the HOME screen, start playing sound, press HOME button, then launch application again from HOME screen. It shouldn't create a new instance of your activity.
Pleae don't set launchMode="singleInstance". This is not necessary and will create more problems than it will solve.
I have a simple, one Activity application.
The problem is that, if i press the BACK button, the application is minimized, but if i try to launch it again, another instance is started.
I know this because my app has plays a sound stream even if is minimized.
How can i maximize the already running instance when trying to launch it ?
I've tried with the code below, but is not working.
android:launchMode="singleInstance"
Android handles this for you. What is probably happening is you're replicating your objects in onCreate thus the "appearance" of 2 activities via a 2nd sound stream.
I don't know what is the C button ? If it is the "back key" so your application is unload from the system, when you start it again, it opens a new instance.
If you press the 'middle key', normally there is only 3 keys on a Android phone, your application is just paused and put in the background, and when you launch it again, the sytem just put your running application from the background to the foreground. No new instance is opened. There are the methods onPause() and onResume() which are triggered in this case.
Hope it can answer to your question
I Have developed an application which contains many activity.
I have noticed an issue while one activity starts another activity and meanwhile if we press camera button or get a call my application hangs and never recovers even after ending the call or closing the camera.
Basically what I want to know is how to handle external interrupts(alarms, calls, camera) so that my app resumes from where it had stopped.
I am replicating this issues on emulator as well as on LG Device.Can anyone give me some idea to how to handle onpause and onrsume function call in this case.
Thanks