textView.setText() Error - Android - android

I am aware there are many forms on StackOverflow about this very topic but none of the fixed worked for me.
When I run the code:
muteText.setText("Testing")
I get an error.
MainActivity.java
//Class Variables
Button startTime;
Button endTime;
TextView muteTime;
TextView unmuteTime;
int hour;
int minute;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Define Variables
startTime = (Button)findViewById(R.id.startButton);
endTime = (Button)findViewById(R.id.endTime);
muteTime = (TextView)findViewById(R.id.muteText);
Log.i("SchedMute", "muteTime: " + muteTime.getText().toString());
unmuteTime = (TextView)findViewById(R.id.unmuteTime);
//Button Listeners
startTime.setOnClickListener(this);
endTime.setOnClickListener(this);
//--\\
hour = 0;
minute = 0;
}
public void onClick(View v){
int id = v.getId();
if(id == R.id.startButton){ //Selecting time 2 Mute phone
showTimePickerDialog(v);
}
}
public void setStartTime(){
muteTime.setText("Testing Testing 123");
}
(Error occurs in last Method (setStartTime))
I am calling the method in another class by doing so:
MainActivity activity = new MainActivity();
activity.setStartTime();
I spend a good 30 minutes trying to figure this one out.
Error:
07-29 12:29:44.034 19958-19958/myApp.com.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: myApp.com.app, PID: 19958
java.lang.NullPointerException
at myApp.com.app.MainActivity$TimePickerFragment.onTimeSet(MainActivity.java:96)
at android.app.TimePickerDialog.tryNotifyTimeSet(TimePickerDialog.java:223)
at android.app.TimePickerDialog.onClick(TimePickerDialog.java:173)
at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:170)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5678)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)

MainActivity activity = new MainActivity();
You can NOT correctly create an instance of an Activity by using new. Never attempt to do this, it will not give you the behaviour you expected.
If you need to call a method in an Activity from a Fragment that is attached to it, you should used the approved approach of using a 'callbacks' interface.
See the following for Communicating with Other Fragments - even though it is about communicating with other Fragments, it is also the way a Fragment should communicate with the Activity it is attached to.

You call to setText before the Activity finished it creation. You need to call the function from the new Activity onCreate().

You should never call the constructor of an Activity. If you do, none of its activity lifecycle will occur. I'm guessing you're doing that in the time picker dialog, you should make that activity be a listener (or pass in an anonymous inner class listener) to handle the set time.

Related

OnCreate called twice (without any sort of configuration change) and app crashes

Please bear with me here, This is an important Intro... and I have been banging my head into the wall with this for a week now.
I have an android app, and one of the big features in the app was already implemented in the old app by another programmer. meaning -> the code does work is the old app, and I want to use it in the new version, but I haven't written it myself, so I am not exactly sure what is going on in there (it should work fine, old app still works).
The issue is this:
In the activity I start using the standard startActivity, the onCreate is called twice for some weird reason.
Now, it has nothing to do with onConfigurationChanged (its not getting called), or any other orientation stuff or something like that.
Another thing is - I tried to put a breakpoint in onCreate to see that its acctaully called twice, but the code stops at the breakpoint only at the first onCreate, and after that the breakpoint isn't caught, even though onCreate is definatly called again.
I check it like this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Long tsLong = System.currentTimeMillis() / 1000;
String ts = tsLong.toString();
Log.i("test", "onCreate() " + ts);
}
What happens is that I see in the log "onCreate() 4444" for example, and after about 3-4 seconds the emulator log is cleared, I see "onCreate() 4448", and the app crashes. So onCreate is called twice, even though I can't catch the second time on breakpoint.
The problem is I have some initiation code
currentCamera = GlobalInfo.getInstance().getCurrentCamera();
cameraPreviewStreamClint = currentCamera.getpreviewStreamClient(); // Line 2
In the first time of onCreate all works well, but in the second time, currentCamera gets null and so the app crashes in Line 2 with a NullPointerException.
Now, I managed to find 4 lines of code, which are in onResume, and when I comment them out, onCreate is called only once and its all good (besides the fact that I obviously need those 4 lines of code to do initiation stuff for the camera). The activity is running but does nothing without those lines.
#Override
protected void onResume() {
super.onResume();
// this code makes the Activity to recreate! onCreate called twice
presenter.submitAppInfo();
presenter.initPreview();
presenter.initStatus();
presenter.addEvent();
}
Again, this is the part of the code which wasn't written by me, so I really dont know what sort of stuff in happening over there.
MY QUESTION IS - What kind of work (threads/ui/anything else) can make an Activity's onCreate method to be called twice, without an ability to debug it???
In the second time the app crashes because of the NullPinterException which is caused because maybe some variable is already "used" in the first onCreate..? I really don't know...
Any ideas/thoughts will be welcomed.. I am really at wit's end with this.
----- EDIT: -----
AndroidManifest.xml looks like this for the activity:
<activity
android:name=".cameraFullVersion.View.Activity.PreviewActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:launchMode="singleTask"
android:theme="#style/AppTheme.NoActionBar"></activity>
I checked, this line of code presenter.submitAppInfo(); doesn't cause the issues, so you can ignore it.
When running onResume like this:
#Override
protected void onResume() {
super.onResume();
// this code makes the Activity to recreate! onCreate called twice
presenter.submitAppInfo();
presenter.initPreview();
// presenter.initStatus();
// presenter.addEvent();
}
Something different happens. the app crashes but without an excpetion you can find in the log, the Info log just says:
09-30 00:59:19.842 10039-10039/com.ofekagmon.apps.ifloat W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x415e5db8)
09-30 00:59:22.852 10039-10039/com.ofekagmon.apps.ifloat I/Process: Sending signal. PID: 10039 SIG: 9
So, with only the first two lines
presenter.submitAppInfo();
presenter.initPreview();
App crashes with Sending signal. PID: 10039 SIG: 9.
And when un-commenting this line (3rd line in onResume): presenter.initStatus();, app crashes and onCreate run twice, as described.
The PreviewPresenter class is pretty big and ugly.. I'll try to put only what relevant.. sorry for that, not my code:
public class PreviewPresenter extends BasePresenter {
private static final String TAG = "PreviewPresenter";
private MediaPlayer videoCaptureStartBeep;
private MediaPlayer modeSwitchBeep;
private MediaPlayer stillCaptureStartBeep;
private MediaPlayer continuousCaptureBeep;
private Activity activity;
private PreviewView previewView;
private CameraProperties cameraProperties;
private CameraAction cameraAction;
private CameraState cameraState;
private PreviewStream previewStream;
private FileOperation fileOperation;
private ICatchWificamPreview cameraPreviewStreamClint;
private MyCamera currentCamera;
private ICatchWificamProperty currentPropertiesClint;
private ICatchWificamControl currentActionClint;
private ICatchWificamState currentStateClint;
private ICatchWificamPlayback currentphotoPlaybackClint;
private ICatchWificamInfo currentInfoClint;
private PreviewHandler previewHandler;
private SDKEvent sdkEvent;
private int curMode = PreviewMode.APP_STATE_NONE_MODE;
private Timer videoCaptureButtomChangeTimer;
public boolean videoCaptureButtomChangeFlag = true;
private Timer recordingLapseTimeTimer;
private int lapseTime = 0;
private List<SettingMenu> settingMenuList;
private boolean allowClickButtoms = true;
private int currentSettingMenuMode;
private int cacheTime;
private WifiSSReceiver wifiSSReceiver;
private Boolean supportStreaming = true;
private long lastCilckTime = 0;
private long lastRecodeTime;
private Tristate ret;
public PreviewPresenter(Activity activity) {
super(activity);
this.activity = activity;
}
// This method is called once from the activity `onCreate`
public void setView(PreviewView previewView) {
this.previewView = previewView;
initCfg(); // Base method from `BasePresenter`
initData();
}
public void initData() {
cameraProperties = CameraProperties.getInstance();
cameraAction = CameraAction.getInstance();
cameraState = CameraState.getInstance();
previewStream = PreviewStream.getInstance();
fileOperation = FileOperation.getInstance();
currentCamera = GlobalInfo.getInstance().getCurrentCamera();
cameraPreviewStreamClint = currentCamera.getpreviewStreamClient();
videoCaptureStartBeep = MediaPlayer.create(activity, R.raw.camera_timer);
stillCaptureStartBeep = MediaPlayer.create(activity, R.raw.captureshutter);
continuousCaptureBeep = MediaPlayer.create(activity, R.raw.captureburst);
modeSwitchBeep = MediaPlayer.create(activity, R.raw.focusbeep);
GlobalInfo.getInstance().enableConnectCheck(true);
previewHandler = new PreviewHandler();
sdkEvent = new SDKEvent(previewHandler);
if (cameraProperties.hasFuction(0xD7F0)) {
cameraProperties.setCaptureDelayMode(1);
}
AppLog.i(TAG, "cameraProperties.getMaxZoomRatio() =" + cameraProperties.getMaxZoomRatio());
}
public void initPreview() {
AppLog.i(TAG, "initPreview curMode=" + curMode);
previewView.setMaxZoomRate(cameraProperties.getMaxZoomRatio());
previewView.updateZoomViewProgress(cameraProperties.getCurrentZoomRatio());
if (cameraState.isMovieRecording()) {
// Code goes into here
AppLog.i(TAG, "camera is recording...");
changeCameraMode(PreviewMode.APP_STATE_VIDEO_CAPTURE, ICatchPreviewMode.ICH_VIDEO_PREVIEW_MODE);
curMode = PreviewMode.APP_STATE_VIDEO_CAPTURE;
startVideoCaptureButtomChangeTimer();
//start recording time timer
startRecordingLapseTimeTimer(cameraProperties.getVideoRecordingTime());
}
//do not start preview,
}
public void initStatus() {
int resid = ThumbnailOperation.getBatteryLevelIcon();
if (resid > 0) {
previewView.setBatteryIcon(resid);
if (resid == R.mipmap.ifloat_icon) {
AppDialog.showLowBatteryWarning(activity);
}
}
IntentFilter wifiSSFilter = new IntentFilter(WifiManager.RSSI_CHANGED_ACTION);
wifiSSReceiver = new WifiSSReceiver();
activity.registerReceiver(wifiSSReceiver, wifiSSFilter);
}
}
See this method initStatus().
When I debug, and on this method, and doing step over, it steps into the ActivityThread.java class and throw the null exception. The line which it happens in is changing.
There are still methods here like:
changeCameraMode(), startVideoCaptureButtomChangeTimer() and startRecordingLapseTimeTimer()
Its just too much to write down.
I'll start with this and hopefully you guys can help me.
Again, the problems lines are:
initStatus() in one of the lines-> Null exception.
And initPreview(); causes App crashes with **Sending signal. PID: 10039 SIG: 9.

Android.Intent[Another activity]

My task: after button pressed, - second activity opening.
Problem: after button pressed, - "application closed unexpectedly".
LogCat said (short version):
04-10 21:25:24.968: E/AndroidRuntime(13032):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{cat.dog.szosta/cat.dog.szosta.ListaOcenActivity}:
java.lang.NullPointerException
LogCat said (full version):
https://drive.google.com/file/d/0B1jfkoUAwYVhYmFvSzBmS2ZIaU0/edit?usp=sharing
First activity code (partial):
private Button mOcenyPrzycisk;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
mOcenyPrzycisk = (Button)findViewById(R.id.ocenyPrzycisk);
mOcenyPrzycisk.setOnClickListener(
new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent intencja = new Intent(MainActivity.this, ListaOcenActivity.class);
startActivity(intencja);
}
}
);
}
Second activity(partial):
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lista_ocen);
mprzyciskWroc = (Button) findViewById(R.id.przyciskWroc);
/*line 28*/ mprzyciskWroc.setOnClickListener(
new View.OnClickListener()
{
public void onClick (View v)
{
finish();
}
}
);
}
P.S: second activity declared in AndroidManifest.xml
I was looking in (didn't help):
Using Intent in an Android application to show another activity
android intents
Thanks in advance!
There is an exception in your second activity. (in ListaOcenActivity)
NullpointerException is thrown at line 28 of your ListaOcenActivity class, in the onCreate method. Search the method generating nullpointer exception, and handle it.
The way you are starting the activity is fine.
04-10 21:25:24.968: E/AndroidRuntime(13032): Caused by: java.lang.NullPointerException
04-10 21:25:24.968: E/AndroidRuntime(13032): at
cat.dog.szosta.ListaOcenActivity.onCreate(ListaOcenActivity.java:28) //here you can see its in your 2nd activity
Problem is here: cat.dog.szosta.ListaOcenActivity.onCreate(ListaOcenActivity.java:28)
Looking at your LogCat (long version) it shows that the NPE is in class ListaOceanActivity line 28. Which means this code is correct. Look into that class instead.

Android: Finding a view by Id without clicking on UI button

New to Android programming, please bear with me.
I am trying to open a settings activity (using Shared Preferences) and populate it with Checkboxes that are set or not set depending on the current settings in the main activity.
I have managed to get it working as long as I put a button on my Settings Activity UI that calls the method to show the status of the Checkboxes as they currently are.
If I try to call the "settingsLoadSavedSettings" method automatically from the onCreate method it won't let me pass the (View view) parameters and without the parameters the app crashes as soon as it tries to run the .isChecked(true) line of code, I think because it can't find the Checkbox by Id without the parameters.
If I comment out the .isChecked(true) lines the program works correctly as far as the Shared Preferenences are being updated and the main app activity responds correctly if I click the checkboxes, but the Checkboxes come up on the Settings UI all unchecked irregardless of the main app settings at start up.
I have it working correctly except that I have to click the "Show Current Settings" button on my Settings UI after the activity loads to show the current state of the Checkboxes. I am trying to populate the Checkboxes status automatically as soon as the activity screen opens.
I left the commented out call in the onCreate method but I can't put View view in as parameters without an error "Cannot resolve symbol 'view'". Again, the settingsLoadSavedSettings method works when called by a button on the settings activity UI and without the View view parameters the app crashes when I try to open the settings activity.
Thank you very much for any help you can offer. I'm hoping this is a simple case of my not understanding Object Oriented Programming and making a bonehead error. I've tried searching for this, but I think that the problem is so generic that my search terms are giving me a huge range of answers
Portion of the code:
public class SettingsActivity extends ActionBarActivity {
CheckBox AllowAddition, AllowSubtraction, AllowMultiplication, AllowDivision;
boolean settingAddition, settingSubtraction, settingMultipliation, settingDivision;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
//settingsLoadSavedSettings(View view);
}
public void settingsLoadSavedSettings(View view){
AllowAddition = (CheckBox) findViewById(R.id.allowAddition);
AllowSubtraction = (CheckBox) findViewById(R.id.allowSubtraction);
AllowMultiplication = (CheckBox) findViewById(R.id.allowMultiplication);
AllowDivision = (CheckBox) findViewById(R.id.allowDivision);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
settingAddition = sharedPreferences.getBoolean("Allow_Addition",true);
settingSubtraction = sharedPreferences.getBoolean("Allow_Subtraction",true);
settingMultipliation = sharedPreferences.getBoolean("Allow_Multiplication",true);
settingDivision = sharedPreferences.getBoolean("Allow_Division",true);
if (settingAddition){
AllowAddition.setChecked(true);
}
if (settingSubtraction){
AllowSubtraction.setChecked(true);
}
if (settingMultipliation){
AllowMultiplication.setChecked(true);
}
if (settingDivision){
AllowDivision.setChecked(true);
}
}
Error Log when Settings Activity Activated with Method call in onCreate:
02-18 20:55:13.916 24918-24918/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mathhelper/com.example.mathhelper.SettingsActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
at android.app.ActivityThread.access$700(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
You're making this way harder than it needs to be- look up PreferenceActivity, which does this for you.
Figured it out.
The problem was that I was calling the .setChecked method before the onCreate was finished which lead to the null pointer error. By adding the method call to a new onStart function, the checkbox is now available to be set.
#Override
protected void onStart(){
super.onStart();
settingsLoadSavedSettings();
}

java.lang.NullPointerException at android.content.ContextWrapper.getPackageName ANDROID

Hey I want to start an Activity from my MainActivity but not in the oncreate method.
public void awe()
{
Intent myIntent = new Intent(MainActivity.this, Awesome.class);
MainActivity.this.startActivity(myIntent);
}
Another class calls the method awe() and what I get is a crash and
05-25 04:06:51.034: E/AndroidRuntime(7161): FATAL EXCEPTION: main
05-25 04:06:51.034: E/AndroidRuntime(7161): java.lang.NullPointerException
05-25 04:06:51.034: E/AndroidRuntime(7161): at android.content.ContextWrapper.getPackageName(ContextWrapper.java:151)
05-25 04:06:51.034: E/AndroidRuntime(7161): at android.content.ComponentName.<init>(ComponentName.java:106)
05-25 04:06:51.034: E/AndroidRuntime(7161): at android.content.Intent.<init>(Intent.java:2895)
05-25 04:06:51.034: E/AndroidRuntime(7161): at package name.MainActivity.awe(MainActivity.java:215)
Someone knows what I can do?
MainActivity
public class MainActivity extends Activity implements OnClickListener {
// (variable stuff)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonE = (Button) findViewById(R.id.buttonEASY);
buttonM = (Button) findViewById(R.id.buttonMED);
// here I do all that button stuff for the layout
}
public void onClick(View arg0) {
System.out.println("click");
if (arg0==buttonE) {
int checkedRadioButton = radioGroup1.getCheckedRadioButtonId();
String radioButtonSelected = "";
switch (checkedRadioButton) {
case R.id.radio0 : radioButtonSelected = "radiobutton1";
Toast.makeText(getApplicationContext(), "Easy, 10 selected", Toast.LENGTH_SHORT).show();
setContentView(R.layout.raten);
// Button stuff, again.
}
public void awe()
{ Intent tutorial = new Intent(MainActivity.this, Awesome.class);
if (tutorial != null) { startActivity(tutorial); }
}
Easy.java
Nothing important here, the place where I refer to awe():
if (s==max+1){System.out.println("AWESOME!"); MainActivity mA = new MainActivity(); mA.awe();}
Awesome.java
public class Awesome extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.awesome);
}
I hope I now posted everything that is important
The problem probably is that MainActivity has not been fully initialized yet when you are calling the awe() method, and the internal Context of the Activity is null.
Things to consider with Android Activities:
Do you have your classes that extend Activity defined in the AndroidManifest.xml?
Are you aware of your Context when using Intents?
For calling intents, always check for null, if you are calling via packagename:
Intent mTutorial = new Intent(MainActivity.this, TutorialActivity.class);
this.startActivity(mTutorial);
Your problem was simply trying to call your "awe()" method was in another Activity that did not have the correct Context for your MainActivity: http://developer.android.com/reference/android/content/Intent.html.
Android Intent requires a "Context" and a "Class".
Update: Here is another post that will help:
Launch an application from another application on Android
Regards,
I got the same error, which took me a while to figure it out.
Like #csgero mentioned, my problem was that the activity I tried to start was not initialized.
It means errors happen before onCreate is called. And it turned out that there was a error in the codes part where I defined the variables in the to-be-called activity. Good luck!
The problem probably is that MainActivity is null. in my case, the activity destroyed when run abvoe code. so the internal Context of the Activity is null.

App is crashing after Home is pressed. Unable to pause - Derived class did not call super.onSaveInstanceState()

When I press the Home button, the app should be paused, save all state and work fine.
Instead I get this error:
java.lang.RuntimeException: Unable to
pause activity
{be.test.tester/be.test.tester.DataScreen}:
java.lang.IllegalStateException:
Derived class did not call
super.onSaveInstanceState() at
android.app.ActivityThread.performPauseActivity(ActivityThread.java:3641)
at
android.app.ActivityThread.performPauseActivity(ActivityThread.java:3598)
at
android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3574)
at
android.app.ActivityThread.access$2500(ActivityThread.java:136)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2186)
at
android.os.Handler.dispatchMessage(Handler.java:99)
at
android.os.Looper.loop(Looper.java:143)
at
android.app.ActivityThread.main(ActivityThread.java:5068)
at
java.lang.reflect.Method.invokeNative(Native
Method) at
java.lang.reflect.Method.invoke(Method.java:521)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at
dalvik.system.NativeStart.main(Native
Method)
Caused by:
java.lang.IllegalStateException:
Derived class did not call
super.onSaveInstanceState() at
android.view.View.dispatchSaveInstanceState(View.java:6087)
at
android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:1207)
at
android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:1207)
at
android.view.View.saveHierarchyState(View.java:6068)
at
com.android.internal.policy.impl.PhoneWindow.saveHierarchyState(PhoneWindow.java:1475)
at
android.app.Activity.onSaveInstanceState(Activity.java:1106)
at
android.app.Activity.performSaveInstanceState(Activity.java:1056)
at
android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1289)
at
android.app.ActivityThread.performPauseActivity(ActivityThread.java:3623)
... 12 more
My activity reacts on touch:
public class DataScreen extends Activity implements OnGestureListener{
I'm getting some extra's from the intent:
totUsage = Integer.parseInt(getIntent().getStringExtra("extraTotUsage"));
limit = Integer.parseInt(getIntent().getStringExtra("extraLimit"));
Bundle bundle = getIntent().getExtras();
mylist = (ArrayList<HashMap<String, String>>) bundle.get("extraMyList");
A custom view is showing data (canvas). When you scroll on screen, data changes in custom view (set, get method) and redraws itself.
I don't really manage the onSaveInstanceState here, don't really know if I have to.
My app is onTop of the stack, because of:
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
I don't understand the error.
You should override onSaveInstanceState and call its super method like shown below. At least it helped me with the same problem.
#Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
// your stuff or nothing
}
#Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
// your stuff or nothing
}
I've just been dealing with this problem. In my app the main activity allows a second activity to be called to display info/instructions etc, it also has a surface view that draws the runtime element of the app.
The main activity has a variable to hold the surface view, if that variable hasn't been set before the info/instructions activity is called I get this error. I simply moved the surface view variable assignment into the main activity onCreate and all is well.
It is also possible that one uses a custom preference (e.g. custom dialog preference) that does not call "super.onSavedInstanceState()" which leads to the same error.

Categories

Resources