Here is another way to transfer data between actions. This is just an example from the tutorial that I followed. I have a splash screen that works for 5 seconds and then it will remove the sound clip from:
@Override protected void onPause() { super.onPause(); ourSong.release(); }
I decided that I want the sound clip to continue playing the next activity, while still being able to kill / release it from there, so I made a sound clip, a MediaPlayer object, open and static, similar to what it was in System. out is a public static object. Being new to Android dev, but not new to Java dev, I did it this way.
import android.app.Activity; import android.content.Intent; import android.media.MediaPlayer; import android.os.Bundle; public class Splash extends Activity { public static MediaPlayer ourSong;
Then, from the next action or any other action, I could access this MediaPlayer object.
public class Menu extends ListActivity { String activities[] = { "Count", "TextPlay", "Email", "Camera", "example4", "example5", "example6" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_expandable_list_item_1, activities)); } @Override protected void onPause() { super.onPause(); Splash.ourSong.release();
Bullshark
source share