Issue
So, i have a video view for my background. There i put image view as button. when i go to other activity and then go back, my video cannot play. just blank. Sorry about my english.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pilih_user);
VideoView videoview = (VideoView) findViewById(R.id.videoView);
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.test);
videoview.setVideoURI(uri);
videoview.start();
ImageView apin = findViewById(R.id.pilihguru);
apin.setOnClickListener(view ->
{
Intent intent = new Intent(PilihUser.this, DaftarPembelajaran.class);
startActivity(intent);
});
}
}
And this my layout. I use constraint and then put video view as background. This my first time to build simple app by java.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layoutpilihuser"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bghome"
tools:context=".PilihUser">
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<ImageView
android:id="@+id/pilihanak"
android:layout_width="200dp"
android:layout_height="94dp"
android:layout_marginTop="64dp"
android:contentDescription="@string/app_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.499"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/videoView"
app:srcCompat="@drawable/pilihuser1" />
<ImageView
android:id="@+id/pilihguru"
android:layout_width="200dp"
android:layout_height="94dp"
android:layout_marginTop="28dp"
android:contentDescription="@string/app_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.499"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pilihanak"
app:srcCompat="@drawable/pilihuser2" />
</android.support.constraint.ConstraintLayout>
Solution
You need to call videoview.start() in onResume:
@Override
public void onResume(){
super.onResume();
videoview.start();
}
Answered By – Klox
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0