I am trying to create a wear android application that has only one action with one fragment inside it. I want to be able to switch fragments based on button clicks or other user actions.
I can replace the fragments just fine; however, when I scroll from the left side of the screen to the right side of the screen. The application is closing. I expected this to act as a back button, rather than exit the application.
Primary activity
import android.support.v4.app.Fragment; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.wearable.view.WatchViewStub; public class MainActivity extends FragmentActivity implements FragmentChangeListener { int fragmentContainerId; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); final WatchViewStub stub = (WatchViewStub)findViewById(R.id.watch_view_stub);
Fragment 1
import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; public class Fragment1 extends Fragment { public Fragment1() {
Fragment 2
import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; public class Fragment2 extends Fragment { public Fragment2() {
FragmentChangeListner
import android.support.v4.app.Fragment; public interface FragmentChangeListener { public void replaceFragment(Fragment fragment); }
When I move from Fragment1 to Fragment2 with a click of a button. How to return to Fragment1 without exiting the application?
source share