Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8102385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:13:47+00:00 2026-06-05T23:13:47+00:00

I am making an android application which has a main activity and several other

  • 0

I am making an android application which has a main activity and several other ones. The main activity(As well as some of the other ones) load data fra SharedPreferences. But, when i launch a new activity, which has some options that can change the data in SharedPreferences that i use in the main activity, and i return to the main activity using the back button, the data there is still the same(Same as before i changed it), somehow i have to reload the data there from SharedPreferences once i return to the main activity, how is this possible??? Please help me and thanks so much in advance!

Main activity code:

package com.mycompanyname.myappname;

import java.util.Calendar;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class myActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
TextView nextAirFilterCleaningTextView, nextPistonChangingTextView, nextOilChangingTextView;
Button manageButton;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    //Import views
    manageButton = (Button)findViewById(R.id.manageButton);
    nextAirFilterCleaningTextView = (TextView)findViewById(R.id.nextAirFilterCleaningTextView);
    nextPistonChangingTextView = (TextView)findViewById(R.id.nextPistonChangingTextView);
    nextOilChangingTextView = (TextView)findViewById(R.id.nextOilChangingTextView);

    //Setup onClickListener for the buttons
    manageButton.setOnClickListener(this);

    //Check if the user has been using his motorcycle
    android.content.Context ctx = getApplicationContext();
    Intent i = new Intent(ctx, UsageActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ctx.startActivity(i);

    //Load first time use screen
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    boolean previouslyStarted = prefs.getBoolean(getString(R.string.pref_previously_started), false);
    if(!previouslyStarted){
    SharedPreferences.Editor edit = prefs.edit();
    edit.putBoolean(getString(R.string.pref_previously_started), Boolean.TRUE);
                edit.commit();
                android.content.Context ctx5 = getApplicationContext();
                Intent i5 = new Intent(ctx5, FirsttimeusageActivity.class);
                i5.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                ctx5.startActivity(i5);
}

    //Load information from SharedPreferences
    SharedPreferences settings = getSharedPreferences("settingsInfo", 0);
    nextAirFilterCleaningTextView.setText("Next air filter cleaning: " + settings.getString("daysTillAirFilterCleaning", "") + " days");
    nextPistonChangingTextView.setText("Next piston changing: " + settings.getString("hoursTillPistonChange", "").toString() + " hours of usage left");
    nextOilChangingTextView.setText("Next oil changing: " + settings.getString("hoursTillOilChange", "").toString() + " hours of usage left");
}
@Override
public boolean onCreateOptionsMenu(Menu meny) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menubuttons, meny);
    return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
    case R.id.NewEvent:
        //Create new calendar event
        Calendar cal = Calendar.getInstance();              
        Intent intent = new Intent(Intent.ACTION_EDIT);
        intent.setType("vnd.android.cursor.item/event");
        intent.putExtra("beginTime", cal.getTimeInMillis());
        intent.putExtra("allDay", true);
        intent.putExtra("rrule", "FREQ=YEARLY");
        intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);
        intent.putExtra("title", "");
        startActivity(intent);
        break;
    case R.id.About:
        //Load about activity and screen
        android.content.Context ctx6 = getApplicationContext();
        Intent i6 = new Intent(ctx6, AboutActivity.class);
        i6.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        ctx6.startActivity(i6);
        break;
    case R.id.settings:
        //Load settings activity and screen
        android.content.Context ctx4 = getApplicationContext();
        Intent i4 = new Intent(ctx4, settingsActivity.class);
        i4.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        ctx4.startActivity(i4);
        break;
    case R.id.Homepage:
        //Load webpage by using custom activity
        android.content.Context ctx = getApplicationContext();
        Intent i = new Intent(ctx, Activity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        ctx.startActivity(i);
        break;
    case R.id.famoustracks:
        android.content.Context ctx7 = getApplicationContext();
        Intent i7 = new Intent(ctx7, Activity.class);
        i7.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        ctx7.startActivity(i7);
        break;
        }
    return true;
}
public void onClick(View src) {
    switch(src.getId()) {
    case R.id.manageButton:
        android.content.Context ctx1 = getApplicationContext();
        Intent i1 = new Intent(ctx1, ManageActivity.class);
        i1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        ctx1.startActivity(i1);
        break;
    }
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:13:48+00:00Added an answer on June 5, 2026 at 11:13 pm

    I fixed it:

    @Override
    public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
        //Load information from SharedPreferences
        SharedPreferences settings = getSharedPreferences("settingsInfo", 0);
        nextAirFilterCleaningTextView.setText("Next air filter cleaning: " + settings.getString("daysTillAirFilterCleaning", "") + " days");
        nextPistonChangingTextView.setText("Next piston changing: " + settings.getString("hoursTillPistonChange", "").toString() + " hours of usage left");
        nextOilChangingTextView.setText("Next oil changing: " + settings.getString("hoursTillOilChange", "").toString() + " hours of usage left");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making an application that has Activity which communicates with a single service,
I am making an android application, which takes an image from camera and then
So, I'm making my first Android application, which basically contains ~250 .txt files in
I am making an application in Android, which requires sending bitmap object from one
I am making an android application in which i have five items in a
Friends i am making an application in which i am using Map Activity. Now
I am making an android application in which I have put 10 images and
I am making an application for android which should show pictures (i was already
I am an android developer.I am making an application in which I have to
im making an android application which requires a user to register using a form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.