Advertisement
knight109

Minimal Application

Feb 3rd, 2022
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. public class FragmentEvent extends Fragment {
  2.  
  3.     Button scanner;
  4.  
  5.     private final ActivityResultLauncher<ScanOptions> fragmentLauncher = registerForActivityResult(new ScanContract(),
  6.             result -> {
  7.                 Log.i(TAG, "On Scanner Launcher.....");
  8.                 if(result.getContents() == null) {
  9.                     Toast.makeText(getContext(), "Cancelled from fragment", Toast.LENGTH_LONG).show();
  10.                 } else {
  11.                     Toast.makeText(getContext(), "Scanned from fragment: " + result.getContents(), Toast.LENGTH_LONG).show();
  12.                 }
  13.             });
  14.  
  15.     public FragmentEvent() {
  16.     }
  17.  
  18.     @Override
  19.     public View onCreateView(LayoutInflater inflater, ViewGroup container,
  20.                              Bundle savedInstanceState) {
  21.         View view = inflater.inflate(R.layout.fragment_event, container, false);
  22.         Button scan = view.findViewById(R.id.scanner);
  23.         scan.setOnClickListener(v -> scanFromFragment());
  24.         Log.i(TAG, "On Create .....");
  25.         return view;
  26.     }
  27.  
  28.     public void scanFromFragment() {
  29.         Log.i(TAG, "On Scanner Initialization.....");
  30.         fragmentLauncher.launch(new ScanOptions());
  31.     }
  32.  
  33.     @Override
  34.     public void onResume() {
  35.         super.onResume();
  36.         Log.i(TAG, "On Resume .....");
  37.     }
  38.  
  39.     @Override
  40.     public void onDestroy() {
  41.         super.onDestroy();
  42.         Log.i(TAG, "On Destroy .....");
  43.     }
  44.  
  45.     @Override
  46.     public void onPause() {
  47.         super.onPause();
  48.         Log.i(TAG, "On Pause .....");
  49.     }
  50.  
  51.     @Override
  52.     public void onStart() {
  53.         super.onStart();
  54.         Log.i(TAG, "On Start .....");
  55.     }
  56.  
  57.     @Override
  58.     public void onStop() {
  59.         super.onStop();
  60.         Log.i(TAG, "On Stop .....");
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement