Skip to content

Commit d5a41ce

Browse files
committed
put PApplet.onCreate() call in PGragment.onCreateView()
1 parent f601ab3 commit d5a41ce

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

core/src/processing/android/PFragment.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,22 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
159159
Bundle savedInstanceState) {
160160
if (sketch != null) {
161161
sketch.initSurface(inflater, container, savedInstanceState, this, null);
162+
163+
// For compatibility with older sketches that run some hardware initialization
164+
// inside onCreate(), don't call from Fragment.onCreate() because the surface
165+
// will not be yet ready, and so the reference to the activity and other
166+
// system variables will be null. In any case, onCreateView() is called
167+
// immediately after onCreate():
168+
// https://developer.android.com/reference/android/app/Fragment.html#Lifecycle
169+
sketch.onCreate(savedInstanceState);
170+
162171
return sketch.getSurface().getRootView();
163172
} else {
164173
return null;
165174
}
166175
}
167176

168177

169-
@Override
170-
public void onCreate(Bundle savedInstanceState) {
171-
super.onCreate(savedInstanceState);
172-
if (sketch != null) sketch.onCreate(savedInstanceState);
173-
}
174-
175-
176178
@Override
177179
public void onStart() {
178180
super.onStart();

0 commit comments

Comments
 (0)