私のアプリのメイン アクティビティは FragmentActivity を拡張し、電話で他のアプリに移行することで一時停止および再開されたときに正しく機能します。
@Override
protected void onCreate(Bundle savedInstanceState) {
...
..
.
mPagerAdapter = new MyPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mPagerAdapter);
mViewPager.setCurrentItem(PAGE_No / 2);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.my_pager, container, false);
...
..
.
mGridView.setAdapter(new CellAdapter(rootView.getContext(), x,y));
return rootView;
}
ただし、ActivityManager によって強制終了された場合 (ActivityManager: プロセス com.androcn.aaa.bbb (pid 16471) が死亡しました。) 受信: Unable to start activity: NullPointerException , from compiler once it re-launch it:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androcn.aaa.bbb/com.androcn.aaa.bbb.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2351)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$600(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5485)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.androcn.aaa.bbb.MainActivity$MonthViewFragment.onCreate(MainActivity.java:162)
at android.support.v4.app.Fragment.performCreate(Fragment.java:1437)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:877)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1070)
at android.support.v4.app.FragmentManagerImpl.dispatchCreate(FragmentManager.java:1856)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:210)
at com.androcn.aaa.bbb.MainActivity.onCreate(MainActivity.java:77)
at android.app.Activity.performCreate(Activity.java:5066)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
... 11 more
誰かがこれについて私を助けてくれれば幸いです。