I have an application with a list of video files with play button. When the user clicks play button, a separate activity starts through intent where the video is played. What I want is that when I click the back button when the video file finishes, I want the mainActivity to be refreshed (the mainActivity is the activity that started the activity for playing video file).
Any useful suggestions please??
Put your "refresh"-code in the Main-Activity's onStart-method.
See Androids Activity Lifecycle.
You could use startActivityForResult(Intent, int) and then handle the different results.
Related
My Activity contains webView. Sometimes webView contains video. When watching the video in webView and press the back button, I go on to another Activity, but the video continues to play and I hear the sound of video. How can I solve this problem? Thank you in advance.
Couple different options:
if you want to completely stop the video, make sure you call finish() when clicking back.
You can do that like this on your Activity:
#Override
public void onBackPressed() {
this.finish();
}
Activity will be destroyed and video will stop.
If you want to stop the video but not destroy the activity, edit your question and show some of your code so I can give you more options.
This is a solution that works for me: How to stop youtube video playing in Android webview?
mWebView.onPause();
I have developed an Android app, in which I have created 3 activities. When the app starts, the MainActivity launches the ImageActivity for playing images from the sdcard/Video folder of an android device.
And I have also a VideoActivity is for playing videos from the sdcard/Video. Means the images and videos are stored only in one folder in the called Video(in sdcard).
Now what I want, if ImageActivity starts to play the images then after finishing the images the VideoActivity should start to play the videos, and again ImageActivity should start then after VideoActivity then ImageActivity, and so on.
I have tried a lot for it, but it is not working. Searched for it on this site, but don't get helpful answer.
You can do this with passing intent with bundle from one activity to another at every single completion of activity. do the same thing in the second activity to start first one.
Intent i = new Intent(firstactivity.this,secondactivity.class);
Bundle b= new Bundle();
bundle.putStringArrayList("list",list); // Here you have to pass your list data
i.putExtras(bundle);
startActivity(i);
This is not a good approach.
It would be better if you use 2 fragments in one Activity. The activity loads the screen again and again but by using a fragment you can inflate those views only.
You should create two fragments. One for Image and the second for video.
I have an app that opens a web view and uses a javascript interface to play audio on my Android App. I want the app to close if you hit the back button, which should be happening automatically, but it's not.
The only 2 activities I have are the MainActivity and the WebAppInterface. It's possible that the back button is closing the main activity, but the WebAppInterface for the web view (that also plays the audio) isn't closing when the back button is pressed, but I'm not sure.
Any advice? I would post the code, but there's nothing to see here. A note, I never call
finish();
anywhere in the app, and maybe I should?
I want the app to close if you hit the back button
What your users want is for the music to stop when the user hits the back button. Presumably, you will do that by the same sort of mechanism that you used to start the music in the first place.
A note, I never call finish(); anywhere in the app, and maybe I should?
This happens automatically when the BACK button is pressed, assuming you have not done anything to interfere with it (e.g., overrode onBackPressed() and failed to chain to the superclass).
You can can call finish when you start the WebAppInterface from MainActivity.
Like:
Intent i = new Intent(this, WebAppInterface.class);
startActivity(i);
finish();
This way when you call finish on the WebAppInterface, it won't go back to the MainActivity instead it will close like the MainActivity does.
I am developing media player application in which i am showing a notification when song starts playing in a service.
Basically i am showing a list view in my first activity(being any one from Artist tab, album tab etc) and on click of an item , player screen is shown.
I have to implement a back button in my player activity, i guess i just have to do a finish() on click of it.
But in case my previous activity is destroyed and i am coming through pending intent(through notification), if i call finish() now the activity is simply destroyed. In such case i want to recreate the previous activity.
Example :
Album > player screen is shown and songs starts in service with status bar notification..
Suppose i press back now and destroy all the activity.
Click on notification > Player is shown again.. if i press back now Album activity should be shown similarly for artist tab.
So far i am just doing:
btnBack.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
I guess you can achieve what you need with setting the intent flags accordingly. The best introduction to these flags I found is the following
Android Activities and Tasks series – Intent flags
It is still a confusing subject for me yet the Android application offered along with this article is very helpful to check quickly what the different flags do.
I thinking you must set more informations about song in Service like a album and when you press back in song activity you should chek service and give back it from Service and init album activity
I have two activity (A, B):
A: Song Button
B(WebView): Song Play List - Embadded from URL
My question is, when user go to B to start play music and user back to A without stop the music (Music is playing in B)...but when user go to B again the WebView in B is new while the old B is still playing the music. So, how can allow user can go to old B to stop music?
I really stuck on this over a week :((
I do appreciate for your ur help.
You can use the following flag on the intent
myIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
while creating activity B. For more information about this, check the link below
http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_SINGLE_TOP