0

From some reason my app runs in a very laggy way on my new s7 edge but works fine on my old onePlus 2. They both run 6.0.1. I followed this answer but it didn't fix the problems. I checked Memory monitor and saw it allocates 255mb!! and i'm not doing any calculations or using a lot of Bitmaps.

Is there a way to see what is running on the UI Thread?

Is someone familiar with this problem and can help me?

EDIT- SOLUTION:

So apparently some devices struggle to handle images that are loaded via the xml. I set a background image in the MainActivity and that was the reason the app was so laggy. I also did it in the RecycleView and even when it was the same small image in every item it made the app run in a laggy way.

The way to fix this is to set all images dynamically from the code. I used Picasso for that like shown. here

main

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if(notLoggedIn()) {
        startActivity(new Intent(getApplicationContext(), LoginActivity.class));
    }
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycle_view);
    recyclerView.setAdapter(new RecycleViewPostsAdapter(MainActivity.this));
    recyclerView.setLayoutManager(new LinearLayoutManager(this));

}

login

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_login);
    AppEventsLogger.activateApp(this);
    mEmailView = (AutoCompleteTextView) findViewById(R.id.email);

    LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions("email");
    mPasswordView = (EditText) findViewById(R.id.password);
    mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
            if (id == R.id.login || id == EditorInfo.IME_NULL) {
                attemptLogin();
                return true;
            }
            return false;
        }
    });
    final TextView register = (TextView) findViewById(R.id.textView2);
    Button mEmailSignInButton = (Button) findViewById(R.id.sign_in_button);
    mEmailSignInButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            attemptLogin();
        }
    });
    register.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(getApplicationContext(), registerActivity.class));
        }
    });
    mLoginFormView = findViewById(R.id.login_form);
    mProgressView = findViewById(R.id.login_progress);
}

recycleview

  @Override
public void onBindViewHolder(PostsVH holder, int position) {
    switch (position % 5){
        case 0:
            Picasso.with(context).load(R.mipmap.profile1).into(holder.profilePic);
...
Community
  • 1
  • 1
ben
  • 1,064
  • 3
  • 15
  • 29
  • Try to recycle the bitmap – Nithinlal Nov 26 '16 at 10:35
  • one background image using frameLayout – ben Nov 26 '16 at 10:37
  • i thing you have large image so please add this image for different device if not set and set android:largeHeap="true" in manifest file. – Raj Gohel Nov 26 '16 at 10:41
  • One thing that many people miss is that amount of memory consumed by loading a bitmap is related to uncompressed size of the image. The compressed size (i.e. size on disk) of a compressed file such as a .jpg or a .png is often much smaller than the uncompressed size that it consumes in memory once decoded into a bitmap for display. The likely reason for Picasso solving your problem is that it can optimize the image sizes. You could probably do this yourself without Picasso by similarly making the images as small as you can, by reducing the dimensions, the dpi, or both. – GreyBeardedGeek Nov 26 '16 at 16:51

0 Answers0