I'm new to this business, do not kick much! I have 2 fragments in total. The code is fully working, there are no complaints. Only when scrolling through the fragments, the fragments themselves are inhibited, the project was cleaned, the studio was restarted. The fragment code in which I display my fragments and implement the main logic.

public class PageFragment extends Fragment { static final String ARGUMENT_PAGE_NUMBER = "arg_page_number"; static final String TAG = PageFragment.class.getSimpleName(); ImageView[] arr_imageA = new ImageView[3]; ImageView[] arr_imageB = new ImageView[7]; ImageView fab; Animation anim; boolean isClicked; Toast toast; MediaPlayer mediaPlayer; int pageNumber; NotificationManager manager; Notification myNotication; private int[] soundsRawResIds = new int[] {R.raw.belarus, R.raw.russian, R.raw.ukraina, R.raw.litva, R.raw.england, R.raw.japan, R.raw.france}; private int[] buttonIds = new int[] {R.id.b1, R.id.b2, R.id.b3, R.id.b4, R.id.b5 ,R.id.b6, R.id.b7}; private int[] fragments = new int[]{R.id.imageView1,R.id.imageView2,R.id.imageView3}; static PageFragment newInstance(int page) { PageFragment pageFragment = new PageFragment(); Bundle arguments = new Bundle(); arguments.putInt(ARGUMENT_PAGE_NUMBER, page); pageFragment.setArguments(arguments); return pageFragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); anim= AnimationUtils.loadAnimation(getContext(),R.anim.clickbutton); fab(); pageNumber = getArguments().getInt(ARGUMENT_PAGE_NUMBER); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment, container, false); mediaPlayer = new MediaPlayer(); mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mediaPlayer.start(); } }); for (int i = 0; i < fragments.length; i++) { arr_imageA[i] = (ImageView) rootView.findViewById(fragments[i]); arr_imageA[i].setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { v.startAnimation(anim); // mediaPlayer.start(); playSample(R.raw.click_sound); switch (v.getId()) { case R.id.imageView1: startActivity(getActivity(), a1.class); break; case R.id.imageView2://todo копипаст startActivity(getActivity(), a2.class); break; case R.id.imageView3: startActivity(getActivity(), a3.class); break; } } }); if (pageNumber == 1) { View rootViewB = inflater.inflate(R.layout.fragment2, container, false); for (int index = 0; index < buttonIds.length; index++) { arr_imageB[index] = (ImageView) rootViewB.findViewById(buttonIds[index]); } for (int j = 0; j < arr_imageB.length; j++) { arr_imageB[j].setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { v.startAnimation(anim); switch (v.getId()) { case R.id.b1: { stopPlayerIfNeeded(); playSample(soundsRawResIds[0]); } break; case R.id.b2: { stopPlayerIfNeeded(); playSample(soundsRawResIds[1]); } break; case R.id.b3: { stopPlayerIfNeeded(); playSample(soundsRawResIds[2]); } break; case R.id.b4: { stopPlayerIfNeeded(); playSample(soundsRawResIds[3]); } break; case R.id.b5: { stopPlayerIfNeeded(); playSample(soundsRawResIds[4]); } break; case R.id.b6: { stopPlayerIfNeeded(); playSample(soundsRawResIds[5]); } break; case R.id.b7: { stopPlayerIfNeeded(); playSample(soundsRawResIds[6]); } break; } return false; } }); } return rootViewB; } } return rootView; } public void startActivity(final Context activityContext, final Class<? extends Activity> activityClass) { new Handler().postDelayed(new Runnable() { @Override public void run() { startActivity(new Intent(activityContext, activityClass)); } }, 200); } private void fab(){ fab = (ImageView)getActivity().findViewById(R.id.fab); final Animation anim_fab = AnimationUtils.loadAnimation(getContext(), R.anim.fab_animation); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { fab.startAnimation(anim_fab); //если isClicked возращает true fab.setImageResource(isClicked ? R.drawable.speaker_icon_on_shadow : R.drawable.speaker_icon_off_shadow); float volume = isClicked ? 1.0f : 0f; setVolume(volume, volume); toast.makeText(getActivity(), isClicked ? R.string.sound_on : R.string.sound_off, Toast.LENGTH_SHORT).show(); isClicked = !isClicked; } }); } private void playSample(int resid) { AssetFileDescriptor afd = getContext().getResources().openRawResourceFd(resid); try { mediaPlayer.reset(); mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength()); mediaPlayer.prepareAsync(); afd.close(); } catch (IllegalArgumentException e) { Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e); } catch (IllegalStateException e) { Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e); } catch (IOException e) { Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e); } } private void stopPlayerIfNeeded() { if (mediaPlayer.isPlaying()) { mediaPlayer.stop(); } } public void setVolume(float left, float right) { mediaPlayer.setVolume(left, right); } @Override public void onPause(){ if (mediaPlayer.isPlaying()) { // mediaPlayer.stop(); // mediaPlayer.seekTo(0); Notify(); } super.onPause(); } @Override public void onResume(){ super.onResume(); } public void Notify() { Intent intent = new Intent(getActivity(),MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(getActivity(), 1, intent, PendingIntent.FLAG_UPDATE_CURRENT); Notification.Builder builder = new Notification.Builder(getActivity()); builder.setAutoCancel(true); builder.setPriority(Notification.PRIORITY_MAX); builder.setTicker("Потешки-колыбельные"); builder.setContentTitle("Колыбельные"); builder.setContentText("Нажмите чтобы вернуться в приложение"); builder.setSmallIcon(R.drawable.ic_play_circle_filled); builder.setContentIntent(pendingIntent); builder.setOngoing(true); builder.setNumber(100); builder.build(); myNotication = builder.getNotification(); manager = (NotificationManager)getContext().getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(100, builder.build()); } 

}

Adapter class:

 public class MyFragmentPagerAdapter extends FragmentPagerAdapter { static final int PAGE_COUNT = 2; public MyFragmentPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { return PageFragment.newInstance(position); } @Override public CharSequence getPageTitle(int position) { return super.getPageTitle(position); } @Override public int getCount() { return PAGE_COUNT; } } 

Class Maine:

 public class MainActivity extends FragmentActivity { SharedPreferences prefs = null; Intent intent; ViewPager pager; PagerAdapter pagerAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); pager = (ViewPager) findViewById(R.id.pager); pagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager()); pager.setAdapter(pagerAdapter); intent = new Intent(this, First_activity.class); prefs = getSharedPreferences("com.example.navigate.viewpager1", MODE_PRIVATE); } @Override protected void onResume() { super.onResume(); if (prefs.getBoolean("firstrun", true)) { startActivity(intent); prefs.edit().putBoolean("firstrun", false).commit(); } } 

}

And the fragments themselves:

 public class fragment extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment); } } public class fragment2 extends FragmentActivity { LinearLayout linLayout; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment2); } } 

Logs:

 05-07 01:41:44.864 4536-4536/com.example.navigate.viewpager1 I/dalvikvm: Could not find method android.support.v4.app.Fragment.performDestroy, referenced from method com.example.navigate.viewpager1.PageFragment.access$super 05-07 01:41:44.864 4536-4536/com.example.navigate.viewpager1 W/dalvikvm: VFY: unable to resolve virtual method 4144: Landroid/support/v4/app/Fragment;.performDestroy ()V 05-07 01:41:44.864 4536-4536/com.example.navigate.viewpager1 D/dalvikvm: VFY: replacing opcode 0x6f at 0x04d4 05-07 01:41:44.864 4536-4536/com.example.navigate.viewpager1 I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/Fragment;.performLowMemory ()V from Lcom/example/navigate/viewpager1/PageFragment;) 05-07 01:41:44.864 4536-4536/com.example.navigate.viewpager1 I/dalvikvm: Could not find method android.support.v4.app.Fragment.performLowMemory, referenced from method com.example.navigate.viewpager1.PageFragment.access$super 05-07 01:41:44.864 4536-4536/com.example.navigate.viewpager1 W/dalvikvm: VFY: unable to resolve virtual method 4146: Landroid/support/v4/app/Fragment;.performLowMemory ()V 05-07 01:41:44.864 4536-4536/com.example.navigate.viewpager1 D/dalvikvm: VFY: replacing opcode 0x6f at 0x04da 05-07 01:41:44.868 4536-4536/com.example.navigate.viewpager1 I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/Fragment;.performOptionsMenuClosed (Landroid/view/Menu;)V from Lcom/example/navigate/viewpager1/PageFragment;) 05-07 01:41:44.868 4536-4536/com.example.navigate.viewpager1 I/dalvikvm: Could not find method android.support.v4.app.Fragment.performOptionsMenuClosed, referenced from method com.example.navigate.viewpager1.PageFragment.access$super 05-07 01:41:44.868 4536-4536/com.example.navigate.viewpager1 W/dalvikvm: VFY: unable to resolve virtual method 4148: Landroid/support/v4/app/Fragment;.performOptionsMenuClosed (Landroid/view/Menu;)V 05-07 01:41:44.868 4536-4536/com.example.navigate.viewpager1 D/dalvikvm: VFY: replacing opcode 0x6f at 0x052f 05-07 01:41:44.872 4536-4536/com.example.navigate.viewpager1 D/dalvikvm: GC_FOR_ALLOC freed 94K, 4% free 4299K/4476K, paused 4ms, total 4ms 05-07 01:41:44.884 4536-4536/com.example.navigate.viewpager1 I/dalvikvm-heap: Grow heap (frag case) to 19.876MB for 16384012-byte allocation 05-07 01:41:44.888 4536-4545/com.example.navigate.viewpager1 D/dalvikvm: GC_FOR_ALLOC freed <1K, 1% free 20298K/20480K, paused 3ms, total 3ms 05-07 01:41:45.044 4536-4536/com.example.navigate.viewpager1 D/dalvikvm: GC_FOR_ALLOC freed 1K, 1% free 23845K/24028K, paused 1ms, total 1ms 05-07 01:41:45.076 4536-4536/com.example.navigate.viewpager1 D/dalvikvm: GC_FOR_ALLOC freed <1K, 1% free 27455K/27640K, paused 1ms, total 2ms 05-07 01:41:45.108 4536-4536/com.example.navigate.viewpager1 D/dalvikvm: GC_FOR_ALLOC freed 3K, 1% free 31059K/31236K, paused 1ms, total 2ms 05-07 01:41:45.116 4536-4536/com.example.navigate.viewpager1 I/dalvikvm-heap: Grow heap (frag case) to 46.010MB for 16384012-byte allocation 05-07 01:41:45.284 4536-4542/com.example.navigate.viewpager1 D/dalvikvm: GC_FOR_ALLOC freed 1K, 1% free 47057K/47240K, paused 3ms, total 3ms 05-07 01:41:45.396 4536-4536/com.example.navigate.viewpager1 W/FragmentManager: moveToState: Fragment state for PageFragment{527c7008 #1 id=0x7f0d0071 android:switcher:2131558513:1} not updated inline; expected state 3 found 2 05-07 01:41:45.400 4536-4536/com.example.navigate.viewpager1 D/libEGL: loaded /system/lib/egl/libEGL_genymotion.so [ 05-07 01:41:45.400 4536: 4536 D/ ] HostConnection::get() New Host Connection established 0xb7bbc4a0, tid 4536 05-07 01:41:45.408 4536-4536/com.example.navigate.viewpager1 D/libEGL: loaded /system/lib/egl/libGLESv1_CM_genymotion.so 05-07 01:41:45.408 4536-4536/com.example.navigate.viewpager1 D/libEGL: loaded /system/lib/egl/libGLESv2_genymotion.so 05-07 01:41:45.436 4536-4536/com.example.navigate.viewpager1 W/EGL_genymotion: eglSurfaceAttrib not implemented 05-07 01:41:45.440 4536-4536/com.example.navigate.viewpager1 E/OpenGLRenderer: Getting MAX_TEXTURE_SIZE from GradienCache 05-07 01:41:45.440 4536-4536/com.example.navigate.viewpager1 E/OpenGLRenderer: MAX_TEXTURE_SIZE: 16384 05-07 01:41:45.448 4536-4536/com.example.navigate.viewpager1 E/OpenGLRenderer: Getting MAX_TEXTURE_SIZE from Caches::initConstraints() 05-07 01:41:45.448 4536-4536/com.example.navigate.viewpager1 E/OpenGLRenderer: MAX_TEXTURE_SIZE: 16384 05-07 01:41:45.448 4536-4536/com.example.navigate.viewpager1 D/OpenGLRenderer: Enabling debug mode 0 05-07 01:41:45.452 4536-4536/com.example.navigate.viewpager1 I/Choreographer: Skipped 34 frames! The application may be doing too much work on its main thread. 05-07 01:42:11.860 4536-4536/com.example.navigate.viewpager1 W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection 05-07 01:42:17.236 4536-4536/com.example.navigate.viewpager1 W/EGL_genymotion: eglSurfaceAttrib not implemented 05-07 01:42:19.224 4536-4536/com.example.navigate.viewpager1 E/MediaPlayer: Should have subtitle controller already set 05-07 01:42:23.236 4536-4536/com.example.navigate.viewpager1 W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection 05-07 01:42:27.748 4536-4536/com.example.navigate.viewpager1 W/EGL_genymotion: eglSurfaceAttrib not implemented 

Closed due to the fact that the participants are off topic : , aleksandr barakin , VAndrJ , Nick Volynkin 11 May '16 at 6:53 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - aleksandr barakin, Nick Volynkin
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Too many bukaff - niasilil. And why do you persistently activate the fragments and name them with a small letter? ... - YuriySPb
  • @Yuriy SPb understood, I'll get myself out of the hole)) - upward
  • 2
    Also did not master a lot of text. I noticed that you have there arrays ImageView. Displaying pictures for android is a very resource-intensive process. Pay attention to this, maybe you will find something. - Eugene Troyanskii
  • Thank you all, really, the problem is. in pictures, squeezed pictures and lag gone - upward

0