1. There is a little change between the jump mode mentioned here and the usual one:
We can write a jump method in the class inherited by activity for other classes to use, reducing the use of redundant code
Let's look at this method:package com.ayspot.apps.wuliushijie.base; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import butterknife.ButterKnife; /** * Created by sgf on 2016/6/13. */ public abstract class BaseFragment extends Fragment { public Context mContext; // fragment creation @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if(getActivity() == null){ mContext = MyApplication.getContext(); }else{ mContext = getActivity();// Activities on which to rely } } // Initialize layout @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = View.inflate(mContext,getLayoutId(),null); ButterKnife.bind(this, view); return view; } // Initialization layout must be implemented by subclass protected abstract int getLayoutId(); @Override public void onDestroyView() { super.onDestroyView(); ButterKnife.unbind(this); } protected void startActivity(Class cls){ Intent intent = new Intent(mContext,cls); startActivity(intent); } }
Call directly when usingprotected void startActivity(Class cls){ Intent intent = new Intent(mContext,cls); startActivity(intent); }
startActivity(LoginActivity.class);
2. The second one is similar to the one above. The difference is that it is written directly in activity:
Then call in another activity:public static void StartAction(Context context) { Intent intent = new Intent(context, ResumeSearchResultActivity.class); context.startActivity(intent); }
ResumeSearchResultActivity.StartAction(context);
Do you have a better way to share it