更改活动后的活动刷新

时间:2016-11-09 17:26:10

标签: java android

我有3 Activity。 1 - MainActivity,2 - InfoActivity,3 - ChangelogActivity

如果我位于InfoActivity,一切都很好(InfoActivity ProgressBar},如果我转到ChangelogActivity再返回InfoActivity ProgressBar工作正常,他的价值不是0,但如果我从MainActivity转到InfoActivity并返回,则现在ProgerssBar获得价值0。

我如何解决它? 如果需要,我可以在这里放置一些代码。

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.teammt.gmanrainy.huaweifirmwarefinder">

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="21" />

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:configChanges="orientation|screenSize|keyboardHidden|uiMode">
            android:screenOrientation="portrait"
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".FirmwareInfo"
            android:configChanges="orientation|screenSize|keyboardHidden|uiMode"
            android:screenOrientation="portrait" />
        <activity
            android:name=".FirmwareChangelog"
            android:configChanges="orientation|screenSize|keyboardHidden|uiMode"
            android:screenOrientation="portrait" />
        <activity android:name=".SettingsActivity"
            android:configChanges="orientation|screenSize|keyboardHidden|uiMode"
            android:screenOrientation="portrait"></activity>
    </application>

</manifest>

MainActivity Overrided Methods

//Действия во время созданиея MainActivity
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);

        //Конструктор Override
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //Проверка прав
        ActivityCompat.requestPermissions(this, PERMISSION_STRING_ARRAY, REQUEST_PERMISSION_PHONE_STATE);

        //Инициализация
        utils = new FFUtils();
        gridView = (GridView) findViewById(R.id.firmware_grid_view);

        //Установка модели в тайтл
        if(deviceModel != null)
            setTitle(deviceModel);
        else
            setTitle(getString(R.string.app_name));


        ///////////////////////////////////////
        //       Advanced listener блок
        ///////////////////////////////////////

        //Клик по элементу GridView
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View v, int position, long id)
            {
                try
                {
                    System.out.println(lastFirmwares.get(position));
                    String[] lastFirmwareArray = lastFirmwares.get(position).split("\\|");
                    Intent intent = new Intent(getThis(), FirmwareInfo.class);

                    intent.putExtra("firmwareName",lastFirmwareArray[0]).
                            putExtra("firmwareType",lastFirmwareArray[1]).
                            putExtra("firmwareLink",lastFirmwareArray[2]).
                            putExtra("firmwareSize",lastFirmwareArray[3]).
                            putExtra("firmwareLastmod",lastFirmwareArray[4]).
                            putExtra("firmwareCount",lastFirmwares.size()).
                            putExtra("firmwareId",position);

                    startActivity(intent);
                }
                catch (Exception ex)
                {
                    Log.e("GetFirmwarePosition",ex.getMessage());
                }

            }
        });
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putBundle("newBundy", newBundy);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        savedInstanceState.getBundle("newBundy");
    }




    //Действия после загрузки формы
    @Override
    protected void onStart() {
        super.onStart();
        getDelegate().onStart();

        //Получаем список моделей
        modelsList = utils.getModelsList(MODELSLIST_LINK);
        //Получаем приведенную к общему виду модель
        if(modelManuallyChanged == false)
            deviceModel = utils.getDeviceModel(modelsList,utils.getDeviceFullModel());
        //Добавляем модель в тайтл
        setTitle(deviceModel);
    }

InfoActivity Overrided Methods

//Действия во время созданиея FirmwareInfo
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_firmware_info);

    this.setTitle("FirmwareInfo");

    //Инициализация
    utils = new FFUtils();
    firmware_info_lastmod_textview = (TextView)findViewById(R.id.firmware_info_lastmod_textview);
    firmware_info_size_textview = (TextView) findViewById(R.id.firmware_info_size_textview);
    firmware_info_download_progressbar = (ProgressBar) findViewById(R.id.firmware_info_download_progressbar);
    //firmware_info_download_progressbar.setProgress(0);



    //Убираем тень
    getSupportActionBar().setElevation(0);

}



@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}



@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);
    savedInstanceState.putInt("progressbar_progress", firmware_info_download_progressbar.getProgress());
}

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    int progressbar_progress = savedInstanceState.getInt("progressbar_progress");
    firmware_info_download_progressbar.setProgress(progressbar_progress);
}

//Действия после загрузки формы
@Override
protected void onStart() {
    super.onStart();
    getDelegate().onStart();


    firmwareName = getIntent().getExtras().getString("firmwareName");
    firmwareType = getIntent().getExtras().getString("firmwareType");
    firmwareLink = getIntent().getExtras().getString("firmwareLink");
    firmwareSize = getIntent().getExtras().getString("firmwareSize");
    firmwareLastmod = getIntent().getExtras().getString("firmwareLastmod");
    firmwareId = getIntent().getExtras().getInt("firmwareId");
    firmwareCount = getIntent().getExtras().getInt("firmwareCount");


    if(firmwareName != null)
    {
        setTitle(firmwareName + " " + firmwareType);
        firmware_info_lastmod_textview.setText(getString(R.string.last_mod) + " " + firmwareLastmod);
        firmware_info_size_textview.setText(getString(R.string.size) + " " + utils.convertToMegabyte(firmwareSize));
    }
}

Changelog Overrided Methods

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_firmware_changelog);

        //Инициализация
        utils = new FFUtils();
        firmware_changelog_view_model = (TextView)findViewById(R.id.firmware_changelog_view_model);
        firmware_changelog_view_changelog = (TextView)findViewById(R.id.firmware_changelog_view_changelog);
        firmware_changelog_view_changelog.setMovementMethod(new ScrollingMovementMethod());

        //Убираем тень
        getSupportActionBar().setElevation(0);

        //Убираем Titile
        getSupportActionBar().hide();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

    }@Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putBundle("newBundy", newBundy);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        savedInstanceState.getBundle("newBundy");
    }

    //Действия после загрузки формы
    @Override
    protected void onStart() {
        super.onStart();
        getDelegate().onStart();

        firmwareName = getIntent().getExtras().getString("firmwareName");
        firmwareType = getIntent().getExtras().getString("firmwareType");
        firmwareLink = getIntent().getExtras().getString("firmwareLink");
        firmwareSize = getIntent().getExtras().getString("firmwareSize");
        firmwareLastmod = getIntent().getExtras().getString("firmwareLastmod");

        firmware_changelog_view_model.setText(firmwareName);

        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                try
                {
                    //Получаем List со всеми строками feature из changelog
                    parsedChangelog = parseXmlString(prepareXpp(utils.getXmlFromUrl(firmwareLink.replace("update.zip","changelog.xml"))));
                }
                catch (Exception ex)
                {
                    Log.e("Parse error",ex.getMessage());
                }

                StringBuilder sb = new StringBuilder();
                for (String s : parsedChangelog)
                {
                    sb.append(s);
                    sb.append("\t");
                }
                utils.universalSetText(firmware_changelog_view_changelog,sb.toString());
                //firmware_changelog_view_changelog.setText(sb.toString());
            }
        });
        t.start();
    }

0 个答案:

没有答案