简体   繁体   English

每次启动活动都会增加RAM使用量

[英]Activity raises RAM use every time it is started

Alright, so i am sort of confused/frustrated. 好吧,所以我有点困惑/沮丧。

I have a service that is always running and an activity. 我有一个始终在运行的服务和一项活动。 Every time the activity is launched and closed the App memory or ram use raises. 每次启动和关闭活动时,应用程序内存或内存使用率都会提高。

All i have in the activity are images and a seekbar. 我在活动中所拥有的只是图像和搜索栏。

What would i need to do to stop this as it could very quickly build up! 我需要做些什么来阻止这种情况,因为它很快就会堆积起来!

I also have alot of getter and setters. 我也有很多吸气剂和二传手。 Such as tv.getText().toString(); 如tv.getText()。toString(); and bg.setBackgroundResource(R.drawable.icon); 和bg.setBackgroundResource(R.drawable.icon);


So, in my onCreate it starts the ID's for the layouts and etc... every time the activity is created the memory or ram used will significantly raise. 因此,在我的onCreate中,它会启动布局等的ID。每次创建活动时,使用的内存或内存都会大大增加。 Is it duplicating the resources or something? 是在重复资源还是其他? It goes up at a constant rate. 它以恒定的速度上升。

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
    setContentView(R.layout.lock_screen);
    tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

    //DATE & TIME STATS
    DateLayout = (LinearLayout) findViewById(R.id.DateLayout);
    curhour = (TextView) findViewById(R.id.hourText);
    curmin = (TextView) findViewById(R.id.minText);
    curmonth = (TextView) findViewById(R.id.monthText);
    curday = (TextView) findViewById(R.id.dayText);
    curactualday = (TextView) findViewById(R.id.actualdayText);
    batt = (TextView) findViewById(R.id.batt);

    //updateClock();

    //PATHS & TARGETS
    SliderUnlockPath = (ImageView) findViewById(R.id.slider_unlock_path);
    SliderTextAnimation=(AnimationDrawable) SliderUnlockPath.getDrawable();

    //SLIDER
    seekbar = (SeekBar) findViewById(R.id.seekbar);
    seekbar.setOnSeekBarChangeListener( new OnSeekBarChangeListener() 
    {
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
        // TODO Auto-generated method stub
    }

    public void onStartTrackingTouch(SeekBar seekBar) {
        // TODO Auto-generated method stub
        //SliderUnlockPath.setBackgroundResource(R.drawable.lockscreen_slider_path_light);
        SliderUnlockPath.setVisibility(ImageView.INVISIBLE);
    }
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        // TODO Auto-generated method stub
        //SliderUnlockPath.setBackgroundResource(R.drawable.lockscreen_slider_path);

        //IF RIGHTMOST (UNLOCK ZONE)
        int UnlockZone = seekbar.getProgress();
        if (UnlockZone > 86) UnlockZone = 100; {
            seekbar.setProgress(UnlockZone);
            SliderUnlockPath.setVisibility(ImageView.INVISIBLE);                    
        } 
        if (UnlockZone == 100) {
            mHandler.removeCallbacks(mUpdateTimeTask);
            finish();

        }

        //IF NOT RIGHTMOST
        int ResetZone = seekbar.getProgress();
        if (ResetZone < 86) ResetZone = 0; {
            seekbar.setProgress(ResetZone);
            SliderUnlockPath.setVisibility(ImageView.INVISIBLE);
            SliderUnlockPath.setVisibility(ImageView.VISIBLE);
            //SliderUnlockPath.setBackgroundResource(R.drawable.lockscreen_slider_path);
        }
    }
    });




    //WIDGETZONE VIEWFLIPPER
    vf = (ViewFlipper) findViewById(R.id.layoutswitcher);


    //MUSIC
    //MusicLayout = (LinearLayout) findViewById(R.id.MusicLayout);
    //MusicInfoLayout = (LinearLayout) findViewById(R.id.MusicInfoLayout);
    //UpdateMusicOnStart();


    //WEATHER
    WeatherTop = (ImageView) findViewById(R.id.WeatherTop);
    WeatherTopAnimation();

    iconCurrent = (ImageView)findViewById(R.id.iconcurrent);
    CurrentLocation = (TextView)findViewById(R.id.CurrentLocation);
    CurrentHigh = (TextView)findViewById(R.id.CurrentHigh);
    CurrentCondition = (TextView)findViewById(R.id.CurrentCondition);
    //CurrentLow = (TextView)findViewById(R.id.CurrentLow);

    //Get Location from Main Panel
    CurrentLocation.setText(place);

    //STRINGS FOR TEXT INFO
    //String weatherString = QueryGoogleWeather(place);
    //Document weatherDoc = convertStringToDocument(weatherString);
    /*if(parseGoogleWeather(weatherDoc)){
        //Display Result
        String c = currentConditions.condition
                + currentConditions.temp_f
                + currentConditions.temp_c;*/
                //+ currentConditions.humidity
                //+ currentConditions.wind_condition;

        //textCurrent.setText(c);

        /*textInfo.setText("city: " + forecastInformation.city + "\n"
        + "postal code: " + forecastInformation.postal_code + "\n"
        + "forecast date: " + forecastInformation.forecast_date + "\n"
        + "current date time: " + forecastInformation.current_date_time + "\n"
        + "unit: " + forecastInformation.unit_system);*/

    //CurrentLocation.setText(forecastInformation.city);

        //if (iLockerMain.TEMPSCALE.isChecked()) {
            //CurrentHigh.setText(currentConditions.temp_f+"°"+"F");
        //} else {
            //CurrentHigh.setText(currentConditions.temp_c+"°"+"C");
        //}

        //CurrentCondition.setText(currentConditions.condition);

        //Bitmap bm = LoadIcon(currentConditions.icon);
        //iconCurrent.setImageBitmap(bm);

    /*if (CurrentCondition.getText().toString().equals("Overcast")) {
            iconCurrent.setBackgroundResource(R.drawable.cloudy3small);
        } else if (CurrentCondition.getText().toString().equals("Light rain")) {
            iconCurrent.setBackgroundResource(R.drawable.light_rainsmall);
        } else if (CurrentCondition.getText().toString().equals("Light snow")) {
            iconCurrent.setBackgroundResource(R.drawable.snow3small);
        }*/



    mHandler = new Handler();
}

@Override
public void onResume(){
    //updateClock();
    mHandler.removeCallbacks(mUpdateTimeTask);
    mHandler.postDelayed(mUpdateTimeTask, 100);


    super.onResume();
}
@Override
public void onPause(){
    //unregisterReceiver(mReceiver);
    mHandler.removeCallbacks(mUpdateTimeTask);

    super.onPause();
}

您是否要在onDestroy()中释放所有分配?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM