super.onSaveInstanceState does not exist

I’m making an app which has multiple pages, and I’m overriding onSaveInstanceState to save across rotation. But then, I get the error “The function onSaveInstanceState(Bundle) does not exist”. My code is

public void onSaveInstanceState(Bundle savedInstanceState){
    savedInstanceState.putInt("TheInt", page);
    //the variable 'page' is a number that represents which page the app is in
    super.onSaveInstanceState(savedInstanceState);
}

I’m happy to provide more information if anybody needs any.

You need to include imports for that. Try searchin in google: “Android import onSaveInstanceState” and you should get the referenceof the library where it has the line you need to import.

Kf

I tried. I didn’t get anything useful.

Try this:

import android.app.Activity;
import android.os.Bundle;    

I think Activity is defined for you by Processing Android. However, Bundle is the culprit in this case. Include both to be safe.

Kf

Still doesn’t work. I even updated android mode.

Ok, that is odd. Could you post all the error trace here? Also, comment on your Android Mode version, Processing version and OS. I cna try running a quick test in the evening.

Also, can you run a simple example, as what you fnd in the Processing Android webpage? Just to make sure your environments is setup properly.

Kf

There’s no error trace, I saw it in the error tab of Processing. I’ll try compliling it later, because currently I don’t have access to the computer that has my code.

Android mode is 4.0.3, processing is PROCESSING 3.3.6 (REV 0263) - 4 September 2017, OS is windows 10 Home. What do you mean by

The stack trace is

Build folder: C:\Users\KENDE_~1\AppData\Local\Temp\android1530813943716618256sketch
:app:preBuild UP-TO-DATE
:app:preDebugBuild
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:checkDebugManifest
:app:generateDebugBuildConfig
:app:prepareLintJar
:app:generateDebugResValues
:app:generateDebugResources
:app:mergeDebugResources
:app:createDebugCompatibleScreenManifests
:app:processDebugManifest
:app:splitsDiscoveryTaskDebug
:app:processDebugResources
:app:generateDebugSources
:app:javaPreCompileDebug
:app:compileDebugJavaWithJavac----------
1. ERROR in C:\Users\kende_000\AppData\Local\Temp\android1530813943716618256sketch\app\src\main\java\processing\SecurityApp\SecurityApp.java (at line 306)
	super.onSaveInstanceState(savedInstanceState);
	      ^^^^^^^^^^^^^^^^^^^
The method onSaveInstanceState(Bundle) is undefined for the type PApplet
----------
1 problem (1 error)
 FAILED

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\kende_000\AppData\Local\Temp\android1530813943716618256sketch\app\build.gradle' line: 67

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Process 'command 'C:\Users\kende_000\Documents\processing-3.3.6\processing-3.3.6\java\bin\java.exe'' finished with non-zero exit value -1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 58s
14 actionable tasks: 14 executed
org.gradle.tooling.BuildException: Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.3-bin.zip'.
	at org.gradle.tooling.internal.consumer.ExceptionTransformer.transform(ExceptionTransformer.java:51)
	at org.gradle.tooling.internal.consumer.ExceptionTransformer.transform(ExceptionTransformer.java:29)
	at org.gradle.tooling.internal.consumer.ResultHandlerAdapter.onFailure(ResultHandlerAdapter.java:41)
	at org.gradle.tooling.internal.consumer.async.DefaultAsyncConsumerActionExecutor$1$1.run(DefaultAsyncConsumerActionExecutor.java:57)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
	at java.lang.Thread.run(Thread.java:748)
	at org.gradle.tooling.internal.consumer.BlockingResultHandler.getResult(BlockingResultHandler.java:46)
	at org.gradle.tooling.internal.consumer.DefaultBuildLauncher.run(DefaultBuildLauncher.java:77)
	at processing.mode.android.AndroidBuild.gradleBuild(AndroidBuild.java:286)
	at processing.mode.android.AndroidBuild.build(AndroidBuild.java:230)
	at processing.mode.android.AndroidMode.handleRunDevice(AndroidMode.java:315)
	at processing.mode.android.AndroidEditor$15.run(AndroidEditor.java:373)
Caused by: org.gradle.internal.exceptions.LocationAwareException: Build file 'C:\Users\kende_000\AppData\Local\Temp\android1530813943716618256sketch\app\build.gradle' line: 67
Execution failed for task ':app:compileDebugJavaWithJavac'.
	at org.gradle.initialization.DefaultExceptionAnalyser.transform(DefaultExceptionAnalyser.java:74)
	at org.gradle.initialization.MultipleBuildFailuresExceptionAnalyser.transform(MultipleBuildFailuresExceptionAnalyser.java:47)
	at org.gradle.initialization.StackTraceSanitizingExceptionAnalyser.transform(StackTraceSanitizingExceptionAnalyser.java:30)
	at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:137)
	at org.gradle.initialization.DefaultGradleLauncher.executeTasks(DefaultGradleLauncher.java:109)
	at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:78)
	at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:75)
	at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:152)
	at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:100)
	at org.gradle.internal.invocation.GradleBuildController.run(GradleBuildController.java:75)
	at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:53)
	at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
	at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
	at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
	at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$1.run(RunAsBuildOperationBuildActionRunner.java:43)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
	at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:40)
	at org.gradle.tooling.internal.provider.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:51)
	at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:47)
	at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:30)
	at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:39)
	at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:25)
	at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:80)
	at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:53)
	at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:57)
	at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:32)
	at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:36)
	at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:25)
	at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:43)
	at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:29)
	at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:64)
	at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:29)
	at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:59)
	at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:44)
	at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:45)
	at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:30)
	at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
	at org.gradle.util.Swapper.swap(Swapper.java:38)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:62)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:82)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
	at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:295)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDebugJavaWithJavac'.
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
	at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
	at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
	at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
	at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)
	at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
	at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)
	at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
	at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
	at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
	at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
	at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:626)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
	... 3 more
Caused by: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\kende_000\Documents\processing-3.3.6\processing-3.3.6\java\bin\java.exe'' finished with non-zero exit value -1	at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:695)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
	... 29 more

I am referring to something like this

Please, also provide your code or a minimized version of your code that reproduces the problem?

Kf

The example ran just fine.
My code is

import android.app.Activity;
int textSize = 20;
int textSize2 = 20;
int textSize3 = 20;
int textSize4 = 20;
int textSize5 = 20;
int page = 1;
float speed = 0.1;
float x = -20;
boolean sucessful = false;
int numPings = 0;
boolean timedOut = false;
class sizeNText {
  String text;
  int size;
  sizeNText(String text, int size) {
    this.text = text;
    this.size = size;
  }
}
class ipBox {
  int contents;
  int x;
  int y;
  boolean open = false;
  ipBox(int x, int y) {
    this.x = x;
    this.y = y;
    this.contents = 1000;
  }
  void handlePress(int x, int y) {
    textSize(height/16);
    if (this.x < x && this.y < y) {
      if (x < this.x+textWidth("100") && y < this.y+height/16) {
        openKeyboard();
        open = true;
      } else {
        closeKeyboard();
        open = false;
      }
    } else {
      closeKeyboard();
      open = false;
    }
  }
  void handleKey() {
    if (open) {
      println("Key is num "+str(int(key)));
      if (key == '0' || key == '1' || key == '2' || key == '3' || key == '4' || key == '5' || key == '6' || key == '7' || key == '8' || key == '9') {
        if (contents < 26) {
          if (contents == 25) {
            if (int(str(key)) < 6) {
              contents = int(str(contents)+key);
            }
          } else {
            contents = int(str(contents)+key);
          }
        } else if (contents == 1000) {
          contents = int(""+key);
        }
      } else if (key == char(65535)) {
        if (str(contents).length() == 1 || contents == 1000) {
          contents = 1000;
        } else {
          contents = int(str(contents).substring(0, str(contents).length()-1));
        }
      }
    }
  }
  void render() {
    stroke(0);
    fill(255);
    textSize(height/16);
    if (open) {
      strokeWeight(10);
    } else {
      strokeWeight(5);
    }
    rect(this.x, this.y, textWidth("100"), height/16);
    fill(0);
    if (contents != 1000) {
      text(str(contents), this.x, this.y+height/16);
    }
  }
}
class changingText {
  String Text = "";
  int x = 0;
  int y = 0;
  int textSize = 0;
  changingText() {
  }
  void setText(int textSize, int x, int y, String text) {
    this.textSize = textSize;
    this.x = x;
    this.y = y;
    this.Text = text;
  }
  void render() {
    //println("Render was called");
    textSize(this.textSize);
    fill(255, 255, 255);
    println("Height is "+height);
    print("Rendering the text \""+this.Text+"\" at the text size of "+this.textSize+" at the x pos of"+this.x+" and a y pos of "+this.y);
    text(this.Text, this.x, this.y);
  }
}
ipBox text = new ipBox(0, 0);
ipBox text2 = new ipBox(0, 0);
changingText pings = new changingText();
void setup() {
  fullScreen();
  for (int i = 1; i < 1000; i++) {
    textSize(i);
    if (textWidth("SecurePythonPi") > width) {
      i = i / 2;
      textSize = i;
      break;
    }
  }
  for (int i = 1; i < 1000; i++) {
    textSize(i);
    if (textWidth("Search") > width) {
      i = i / 2;
      textSize2 = i;
      break;
    }
  }
  for (int i = 1; i < 1000; i++) {
    textSize(i);
    if (textWidth("Searching...") > width) {
      i = i / 2;
      textSize3 = i;
      break;
    }
  }
  for (int i = 1; i < 1000; i++) {
    textSize(i);
    if (textWidth("Found the device!") > width) {
      i = i / 2;
      textSize4 = i;
      break;
    }
  }
  for (int i = 1; i < 1000; i++) {
    textSize(i);
    if (textWidth("No devices found on that port, sorry. :~(") > width) {
      i = i - 2;
      textSize5 = i;
      break;
    }
  }
  speed = width/300;
  textSize(height/16);
  text = new ipBox(int((width/4)-(textWidth("100")/2)), height/2);
  text2 = new ipBox(int((width/4*3)-(textWidth("100")/2)), height/2);
}
void draw() {
  strokeWeight(5);
  if (page == 1) {
    stroke(0);
    background(100);
    textSize(textSize);
    fill(255);
    text("SecurePythonPi", (width/2)-textWidth("SecurePythonPi")/2, textSize);
    textSize(textSize2);
    fill(100);
    strokeWeight(5);
    rect(width/2-(textWidth("Search")/2), ((textSize2)*0.5)+textSize, textWidth("Search"), textSize2);
    fill(255);
    text("Search", (width/2)-textWidth("Search")/2, ((textSize2)*1.375)+textSize);
  } else if (page == 2) {
    background(100);
    stroke(0);
    line(0, height/10, width, height/10);
    line(width/2-(((height/10)-(height/32))/2), height/64, width/2+(((height/10)-(height/32))/2), height/10-height/64);
    line(width/2+(((height/10)-(height/32))/2), height/64, width/2-(((height/10)-(height/32))/2), height/10-height/64);
    textSize(textSize3);
    fill(255);
    text("Searching...", (width/2)-textWidth("Searching...")/2, textSize3+height/10);
    noStroke();
    ellipse(x, textSize3+height/8, 20, 20);
    x += speed;
    if (x > width+20 || x < -20) {
      speed *= -1;
    }
    if (sucessful) {
      background(100);
      stroke(0);
      line(0, height/10, width, height/10);
      line(width/2-(((height/10)-(height/32))/2), height/64, width/2+(((height/10)-(height/32))/2), height/10-height/64);
      line(width/2+(((height/10)-(height/32))/2), height/64, width/2-(((height/10)-(height/32))/2), height/10-height/64);
      textSize(textSize4);
      fill(255);
      text("Found the device!", (width/2)-textWidth("Found the device!")/2, textSize4+height/10);
    } else if (timedOut) {
      background(100);
      stroke(0);
      line(0, height/10, width, height/10);
      line(width/2-(((height/10)-(height/32))/2), height/64, width/2+(((height/10)-(height/32))/2), height/10-height/64);
      line(width/2+(((height/10)-(height/32))/2), height/64, width/2-(((height/10)-(height/32))/2), height/10-height/64);
      textSize(textSize5);
      fill(255);
      text("No devices found on that port, sorry. :~(", (width/2)-textWidth("No devices found on that port, sorry. :~(")/2, textSize5+height/10);
    } else {
      sizeNText theData = formatPings();
      println("The text is "+theData.text);
      textSize(theData.size);
      pings.setText(theData.size, int((width/2)-(textWidth(theData.text)/2)), height-theData.size, theData.text);
      text.render();
      text2.render();
      pings.render();
    }
  }
}
void checkIP() {
  String[] answer = null;
  int startTime = millis();
  while (answer == null && millis()-startTime<30000 && numPings <= 5) {
    answer = loadStrings("https://192.168."+text.contents+"."+text2.contents+"/");
    if (answer != null) {
      sucessful = true;
      println("Sucess!");
    } else {
      println("No sucess.");
      numPings += 1;
      int lastMillis = millis();
      while (millis() - 2000 < lastMillis) {
        int abc = 5;
      }
    }
  }
  timedOut = answer == null;
}
sizeNText formatPings() {
  String returnVal;
  boolean isOne = numPings == 1;
  int theTextWidth = 20;
  if (isOne) {
    returnVal = "1 ping";
  } else {
    returnVal = str(numPings)+" pings";
  }
  for (int i = 1; i < 1000; i++) {
    textSize(i);
    if (textWidth(returnVal) > width) {
      i = i / 2;
      theTextWidth = i;
      break;
    }
  }
  return new sizeNText(returnVal, theTextWidth);
}
void mousePressed() {
  if (page == 1) {
    textSize(textSize2);
    if (mouseX > width/2-(textWidth("Search")/2) &&  mouseX < width/2+(textWidth("Search")/2)) {
      if (mouseY > ((textSize2)*0.5)+textSize && mouseY < ((textSize2)*1.5)+textSize) {
        page = 2;
        sucessful = false;
        numPings = 0;
        timedOut = false;
        thread("checkIP");
        println("Tap ocurred");
      }
    }
  } else if (page == 2) {
    text.handlePress(mouseX, mouseY);
    text2.handlePress(mouseX, mouseY);
    if (mouseY < height/10) {
      page = 1;
      x = -20;
    }
  }
}
void keyPressed() {
  text.handleKey();
  text2.handleKey();
}
public void onSaveInstanceState(Bundle savedInstanceState){
    savedInstanceState.putInt("TheInt", page);
    //the variable 'page' is a number that represents which page the app is in
    super.onSaveInstanceState(savedInstanceState);
}```

@KTibow===

Though your code is not ok for what you want to do (no import for bundle and not any call to retrieve it: savedInstanceState.getInt(your tag, your int value), i think that there is no way to use savedIntanceState with P5. First reason is that the call to this method is never fired “automatically” as it is supposed to be; you can verify it adding some println to your method; now you can also make a call yourself, though it is not easy because the exact moment for calling that is not very precise: "after - or before - onPause() and before onStop() " say the docs; let us try to do that after onPause() and super.on Pause:here you add something like Bundle b = new Bundle() and call to the saveInstanceState method with b as arg. Then add also some println(): you can see that the event is fired and that your int is supposed to be saved: but, when you try to get it, it is null (you can try using onstart(), on ActivityCreated and at every moment of the lifeCycle for fragments) and always null. Why? - Because your int value is not saved in the Activity which creates or recreates the fragment; for avoiding that you have to use super.onSavedInstanceState, as you have tried to do. But what is super using P5? - It is not the main activity which creates the fragment, it refers to PApplet that your sketch is extending and PApplet knows nothing about it, as you can verify loooking at the source code for the android mode: “super” has sense for it only in some simple cases like onPause() and so on: that is why your call even “forced” to the onSavedInstanceState() method does nothing (as it must happen) if you uncomment super and fires an error when adding super… Sorry! i cannot see anyway to solve that except to try some workaround using SavePreferences instead of the bundle…Or using Android Studio and modifying the main Activity created by P5.

@KTibow===
finally i got an idea (in some sense it is a bad idea but…): i suppose that you want to have the same values for your int (pages) even when there is a change in the orientation of the phone. Is it true? - In this case you have 2 solutions: first one is to use set retaininstance(true) on the fragment in which is the sketch; but in order to do that you have to “find” this fragment; normally you can do that using FragmentManager and findViewById or find by tag: looking to the mainActivity from P5 i see that the fragment has a tag (“main-fragment”) and i have tried to get it this way: no chance, i dont know exacltly why (perhaps because the fragment is not a Fragment but a “PFragment”, perhaps because this tag is “private”. So there is only one solution: that is using the Manifest and adding to it the config changes tag which means that you are taking care of config changes yourself in the code. I have tried this solution and it works: my values are not destroyed when the orientation changes, hurrah! - Remains one problem= what happens if the user hits the back button??? - In this case my values are destroyed and that is the case to use sharedPreferences…

Using onPause, onStart, and saveStrings worked! Thanks!

@KTibow====

yes, saveStrings with onPause() has to work: it is quite the same solution than SharedPreferences in your case, though SharedPreferences, in other cases, permits to save a lot of things (int, floats, arrays, boolean …) in a hash map… like a bundle!