Clearing the SharedPreference data after some specified time
I am using SharedPreference
in my application. When application is started I am saving some data in it. I have one Activity
on which I am performing all Fragment
operations like adding, replacing etc. I need to remove that stored data from preference if I am not performing any actions in application i.e. application is idle for some time. How to detect that user is not performing some operations in app and remove data from preference after some specified time when app is stable?
android android-fragments android-activity sharedpreferences
add a comment |
I am using SharedPreference
in my application. When application is started I am saving some data in it. I have one Activity
on which I am performing all Fragment
operations like adding, replacing etc. I need to remove that stored data from preference if I am not performing any actions in application i.e. application is idle for some time. How to detect that user is not performing some operations in app and remove data from preference after some specified time when app is stable?
android android-fragments android-activity sharedpreferences
Have you checked this?
– Piyush
Dec 27 at 13:25
One way to use rx. This library can be useful for your task github.com/JakeWharton/RxBinding
– Artem Botnev
Dec 27 at 13:28
add a comment |
I am using SharedPreference
in my application. When application is started I am saving some data in it. I have one Activity
on which I am performing all Fragment
operations like adding, replacing etc. I need to remove that stored data from preference if I am not performing any actions in application i.e. application is idle for some time. How to detect that user is not performing some operations in app and remove data from preference after some specified time when app is stable?
android android-fragments android-activity sharedpreferences
I am using SharedPreference
in my application. When application is started I am saving some data in it. I have one Activity
on which I am performing all Fragment
operations like adding, replacing etc. I need to remove that stored data from preference if I am not performing any actions in application i.e. application is idle for some time. How to detect that user is not performing some operations in app and remove data from preference after some specified time when app is stable?
android android-fragments android-activity sharedpreferences
android android-fragments android-activity sharedpreferences
edited Dec 27 at 14:02
Fantômas
32.3k156288
32.3k156288
asked Dec 27 at 13:21
Satyam
178112
178112
Have you checked this?
– Piyush
Dec 27 at 13:25
One way to use rx. This library can be useful for your task github.com/JakeWharton/RxBinding
– Artem Botnev
Dec 27 at 13:28
add a comment |
Have you checked this?
– Piyush
Dec 27 at 13:25
One way to use rx. This library can be useful for your task github.com/JakeWharton/RxBinding
– Artem Botnev
Dec 27 at 13:28
Have you checked this?
– Piyush
Dec 27 at 13:25
Have you checked this?
– Piyush
Dec 27 at 13:25
One way to use rx. This library can be useful for your task github.com/JakeWharton/RxBinding
– Artem Botnev
Dec 27 at 13:28
One way to use rx. This library can be useful for your task github.com/JakeWharton/RxBinding
– Artem Botnev
Dec 27 at 13:28
add a comment |
1 Answer
1
active
oldest
votes
You can achieve it by adding thread on your parent activity / anywheve in the app which you or your app can access without any object initialization.
Declare Handler
private Handler handlerClearPref;
Add inside onCreate()
handlerClearPref = new Handler();
handlerClearPref.postDelayed(runnableClearPref, 20000);
Add inside Activity
class out out of onCreate
Method
private Runnable runnableClearPref = new Runnable() {
@Override
public void run() {
// Code to clear your Shared Preference contents.
handlerCheckEventNotification.postDelayed(runnableClearPref, 20000);
}
};
Above code will clear your prefrence at every 20 second.
And if you want to stop this thread then you can use below code.
handlerClearPref.removeCallbacks(runnableClearPref);
New contributor
How does this answer handles the inactivity functionality which is requested?
– Nero
Dec 27 at 14:28
Yes, you are correct. I have answered this for the query related to clear preference at specified time. For the user's inactivity, i think @satyam should go with the link provided by Piyus in comment.
– Ajay Mehta - Rlogical
Dec 27 at 14:39
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945790%2fclearing-the-sharedpreference-data-after-some-specified-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can achieve it by adding thread on your parent activity / anywheve in the app which you or your app can access without any object initialization.
Declare Handler
private Handler handlerClearPref;
Add inside onCreate()
handlerClearPref = new Handler();
handlerClearPref.postDelayed(runnableClearPref, 20000);
Add inside Activity
class out out of onCreate
Method
private Runnable runnableClearPref = new Runnable() {
@Override
public void run() {
// Code to clear your Shared Preference contents.
handlerCheckEventNotification.postDelayed(runnableClearPref, 20000);
}
};
Above code will clear your prefrence at every 20 second.
And if you want to stop this thread then you can use below code.
handlerClearPref.removeCallbacks(runnableClearPref);
New contributor
How does this answer handles the inactivity functionality which is requested?
– Nero
Dec 27 at 14:28
Yes, you are correct. I have answered this for the query related to clear preference at specified time. For the user's inactivity, i think @satyam should go with the link provided by Piyus in comment.
– Ajay Mehta - Rlogical
Dec 27 at 14:39
add a comment |
You can achieve it by adding thread on your parent activity / anywheve in the app which you or your app can access without any object initialization.
Declare Handler
private Handler handlerClearPref;
Add inside onCreate()
handlerClearPref = new Handler();
handlerClearPref.postDelayed(runnableClearPref, 20000);
Add inside Activity
class out out of onCreate
Method
private Runnable runnableClearPref = new Runnable() {
@Override
public void run() {
// Code to clear your Shared Preference contents.
handlerCheckEventNotification.postDelayed(runnableClearPref, 20000);
}
};
Above code will clear your prefrence at every 20 second.
And if you want to stop this thread then you can use below code.
handlerClearPref.removeCallbacks(runnableClearPref);
New contributor
How does this answer handles the inactivity functionality which is requested?
– Nero
Dec 27 at 14:28
Yes, you are correct. I have answered this for the query related to clear preference at specified time. For the user's inactivity, i think @satyam should go with the link provided by Piyus in comment.
– Ajay Mehta - Rlogical
Dec 27 at 14:39
add a comment |
You can achieve it by adding thread on your parent activity / anywheve in the app which you or your app can access without any object initialization.
Declare Handler
private Handler handlerClearPref;
Add inside onCreate()
handlerClearPref = new Handler();
handlerClearPref.postDelayed(runnableClearPref, 20000);
Add inside Activity
class out out of onCreate
Method
private Runnable runnableClearPref = new Runnable() {
@Override
public void run() {
// Code to clear your Shared Preference contents.
handlerCheckEventNotification.postDelayed(runnableClearPref, 20000);
}
};
Above code will clear your prefrence at every 20 second.
And if you want to stop this thread then you can use below code.
handlerClearPref.removeCallbacks(runnableClearPref);
New contributor
You can achieve it by adding thread on your parent activity / anywheve in the app which you or your app can access without any object initialization.
Declare Handler
private Handler handlerClearPref;
Add inside onCreate()
handlerClearPref = new Handler();
handlerClearPref.postDelayed(runnableClearPref, 20000);
Add inside Activity
class out out of onCreate
Method
private Runnable runnableClearPref = new Runnable() {
@Override
public void run() {
// Code to clear your Shared Preference contents.
handlerCheckEventNotification.postDelayed(runnableClearPref, 20000);
}
};
Above code will clear your prefrence at every 20 second.
And if you want to stop this thread then you can use below code.
handlerClearPref.removeCallbacks(runnableClearPref);
New contributor
edited 2 days ago
Android
32113
32113
New contributor
answered Dec 27 at 13:43
Ajay Mehta - Rlogical
514
514
New contributor
New contributor
How does this answer handles the inactivity functionality which is requested?
– Nero
Dec 27 at 14:28
Yes, you are correct. I have answered this for the query related to clear preference at specified time. For the user's inactivity, i think @satyam should go with the link provided by Piyus in comment.
– Ajay Mehta - Rlogical
Dec 27 at 14:39
add a comment |
How does this answer handles the inactivity functionality which is requested?
– Nero
Dec 27 at 14:28
Yes, you are correct. I have answered this for the query related to clear preference at specified time. For the user's inactivity, i think @satyam should go with the link provided by Piyus in comment.
– Ajay Mehta - Rlogical
Dec 27 at 14:39
How does this answer handles the inactivity functionality which is requested?
– Nero
Dec 27 at 14:28
How does this answer handles the inactivity functionality which is requested?
– Nero
Dec 27 at 14:28
Yes, you are correct. I have answered this for the query related to clear preference at specified time. For the user's inactivity, i think @satyam should go with the link provided by Piyus in comment.
– Ajay Mehta - Rlogical
Dec 27 at 14:39
Yes, you are correct. I have answered this for the query related to clear preference at specified time. For the user's inactivity, i think @satyam should go with the link provided by Piyus in comment.
– Ajay Mehta - Rlogical
Dec 27 at 14:39
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945790%2fclearing-the-sharedpreference-data-after-some-specified-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you checked this?
– Piyush
Dec 27 at 13:25
One way to use rx. This library can be useful for your task github.com/JakeWharton/RxBinding
– Artem Botnev
Dec 27 at 13:28