A portable electronic device comprising: a display; a memory; a sensor configured to detect insertion or removal of a stylus pen; and at least one processor configured to, when the portable electronic device is in an unlocked state: display, on the display, a screen of a first application while the stylus pen is inserted, detect, using the sensor, removal of the stylus pen while the screen of the first application is displayed, when the removal of the stylus pen is detected: execute a second application in response to the removal of the stylus pen, and identify information, stored in the memory, including a previously generated handwritten memo associated with the second application acquired before detection of the removal of the stylus pen, and display, on the display, a screen of the second application including the previously generated handwritten memo, and when the insertion of the stylus pen is detected: terminate display of the screen of the second application; and display, on the display, the screen of the first application or a screen of a default page. a display; a memory; a sensor configured to detect insertion or removal of a stylus pen; and at least one processor configured to, when the portable electronic device is in an unlocked state: display, on the display, a screen of a first application while the stylus pen is inserted, detect, using the sensor, removal of the stylus pen while the screen of the first application is displayed, when the removal of the stylus pen is detected: execute a second application in response to the removal of the stylus pen, and identify information, stored in the memory, including a previously generated handwritten memo associated with the second application acquired before detection of the removal of the stylus pen, and display, on the display, a screen of the second application including the previously generated handwritten memo, and when the insertion of the stylus pen is detected: terminate display of the screen of the second application; and display, on the display, the screen of the first application or a screen of a default page. display, on the display, a screen of a first application while the stylus pen is inserted, detect, using the sensor, removal of the stylus pen while the screen of the first application is displayed, when the removal of the stylus pen is detected: execute a second application in response to the removal of the stylus pen, and identify information, stored in the memory, including a previously generated handwritten memo associated with the second application acquired before detection of the removal of the stylus pen, and display, on the display, a screen of the second application including the previously generated handwritten memo, and when the insertion of the stylus pen is detected: terminate display of the screen of the second application; and display, on the display, the screen of the first application or a screen of a default page. execute a second application in response to the removal of the stylus pen, and identify information, stored in the memory, including a previously generated handwritten memo associated with the second application acquired before detection of the removal of the stylus pen, and display, on the display, a screen of the second application including the previously generated handwritten memo, and when the insertion of the stylus pen is detected: terminate display of the screen of the second application; and display, on the display, the screen of the first application or a screen of a default page. terminate display of the screen of the second application; and display, on the display, the screen of the first application or a screen of a default page.