I have a simple QR code scanning app. Here's the flowchart which describes its logic.
And this is the main part:
import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
public class ScanActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan);
}
#Override
protected void onResume() {
super.onResume();
IntentIntegrator scanIntegrator = new IntentIntegrator(ScanActivity.this);
scanIntegrator.setOrientationLocked(false);
scanIntegrator.initiateScan();
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (scanResult != null){
String strResult = scanResult.getContents();
Intent iii = new Intent(ScanActivity.this, ScanResultActivity.class);
iii.putExtra("scan_result", strResult);
startActivity(iii);
}
}
#Override
public void onBackPressed() {
moveTaskToBack(true);
}
}
If you are in ScanActivity, then the app will immediately display ScanResultActivity after scanning, which is as expected. The only issue is app won't quit when Back key is pressed. Instead, it will jump to ScanResultActivity. Of course, the scanning result is null.
How to quit the app by pressing Back key when scanning is running?
Full code: https://github.com/anta40/QRScanDemo
this method
#Override
public void onBackPressed() {
moveTaskToBack(true);
}
should call the super method, like this
#Override
public void onBackPressed() {
super.onBackPressed();
}
Related
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
public class ReaderActivity extends AppCompatActivity {
private Button scan_btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reader);
scan_btn = (Button) findViewById(R.id.scan_btn);
final Activity activity = this;
scan_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
integrator.setPrompt("Scan");
integrator.setCameraId(0);
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(false);
integrator.initiateScan();
}
});
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result.getContents() != null) {
if(result.getContents().equals("Electronics A1")){
Toast.makeText(this, "You cancelled the scanning", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(this, result.getContents(),Toast.LENGTH_LONG).show();
}
}
else {
super.onActivityResult(requestCode, resultCode, data);
}
}
}
Hi all, currently doing a project for my school.
now im having problems with the program.
if(result.getContents() != null) {
if(result.getContents().equals("Electronics A1")){
Toast.makeText(this, "You cancelled the scanning", Toast.LENGTH_LONG).show();
curently this if stament is being ignored by the app.
the purpose of the statement is when i scan a specific qr code it will move to a new activity or do something.
yesterday the statement was working but suddenly today it wont work......
can you guys help me?
currently new to android studio
When I put setResult() in the onClickListener of a button, that works. However, if I put it in onPause(), onStop() or onDestroy(), that never works.
I got really confused about that.
Here is the code of MainActivity.
package com.example.hellotest;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
private static final String TAG = MainActivity.class.getSimpleName();
private Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
startActivityForResult(new Intent(getApplicationContext(), SecondActivity.class), 0);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK) {
Toast.makeText(getApplicationContext(), "hello world", Toast.LENGTH_SHORT).show();
Log.d(TAG, "RESULT_OK");
} else {
Toast.makeText(getApplicationContext(), "result not ok", Toast.LENGTH_SHORT).show();
Log.d(TAG, "RESULT_CANCELED");
}
}
}
Here is the SecondActivity.
package com.example.hellotest;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class SecondActivity extends Activity {
private static final String TAG = SecondActivity.class.getSimpleName();
private Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// setResult(RESULT_OK);
Log.d(TAG, "button on click");
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.second, menu);
return true;
}
#Override
protected void onDestroy() {
setResult(RESULT_OK);
Log.d(TAG, "onDestroy");
super.onDestroy();
}
#Override
protected void onPause() {
// setResult(RESULT_OK);
Log.d(TAG, "onPause");
super.onPause();
}
#Override
protected void onStop() {
// setResult(RESULT_OK);
Log.d(TAG, "onStop");
super.onStop();
}
}
And here is the Log of which I put setResult() in the onClick()
11-21 00:07:54.243: D/SecondActivity(4790): button on click
11-21 00:07:56.364: D/SecondActivity(4790): onPause
11-21 00:07:57.813: D/SecondActivity(4790): onStop
11-21 00:07:57.813: D/SecondActivity(4790): onDestroy
11-21 00:07:56.404: D/MainActivity(4790): RESULT_OK
But if in onDestroy()
11-21 00:10:08.125: D/SecondActivity(4846): onPause
11-21 00:10:09.456: D/SecondActivity(4846): onStop
11-21 00:10:09.456: D/SecondActivity(4846): onDestroy
11-21 00:10:08.176: D/MainActivity(4846): RESULT_CANCELED
I have no idea about that.
You can also override finish() and set the result before calling into the super class:
#Override
public void finish() {
setResult(...);
super.finish();
}
Call setResult() when the user performs the operation that selects the result. onPause() or later lifecycle events are too late.
startActivityForResult() is designed for "picker" sorts of activities, where the user is picking something. The typical pattern is for you to call setResult() and finish() once the user has picked their item.
This question already has answers here:
How to start new activity on button click
(28 answers)
Closed 8 years ago.
I am trying to write a code in Android to pass a value from a button click to another class. I am getting 0 value in the Log and i am not finding any technique to send the proper value.
Please go through my below code :
Java Code:
MainActivity.java
package com.example.mybuttonvalue;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
public class MainActivity extends Activity
{
Activity activity;
Context cont;
public static int mysum;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button)findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
Intent intent = new Intent(MainActivity.this,MySum.class);
intent.putExtra("key",5);
startActivityForResult(intent,2);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
// check if the request code is same as what is passed here it is 2
if(requestCode==2)
{
}
} }
MySum.java
package com.example.mybuttonvalue;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
public class MySum extends Activity
{
Activity activity;
Context context;
int value = getIntent().getIntExtra("key",0); // 0 is default vlaue
public MySum(Activity activity,Context cont)
{
this.activity = activity;
this.context = cont;
}
public void check(final int x)
{
final Dialog dia = new Dialog(context);
dia.requestWindowFeature(dia.getWindow().FEATURE_NO_TITLE);
dia.setContentView(R.layout.check);
Button btn = (Button) dia.findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
int no = 12+x;
myvalue(no);
Intent intent= getIntent();
intent.putExtra("result",x);
setResult(2,intent);
dia.dismiss();
}
});
dia.show();
}
public String myvalue(int x)
{
return String.valueOf(x);
}
}
Log Report
05-18 23:04:29.603: D/My Value :(10375): 0
This is the above code , how can i get 17 in the Log. I should get the result from MySum class to MainActivity class.
Please let me know , suggest me some good solution.
You are instantiating a Activity class public class MySum extends Activity which is wrong
MySum my = new MySum(MainActivity.this,MainActivity.this);
Remove the constructor and the above code.
You need to use intent to pass values between activities. To get value back in MainActivity use startActivityForResult and override onActivityResult and get the value using intent.
Example:
In MainActivity.java
Intent intent = new Intent(MainActivity.this,MySum.class);
intent.putExtra("key",5);
startActivityForResult(intent,2);
Then override onActivityResult
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
// check if the request code is same as what is passed here it is 2
if(requestCode==2)
{
//get data using intent
int result = data.getIntextra("result",0);
}
}
In MySum.java
int value = getIntent().getIntExtra("key",0); // 0 is default vlaue
Do operation on value
Then to return result
Intent intent= getIntent();
intent.putExtra("result",x);
setResult(2,intent);
Edit:
public class MySum extends Activity
{
#Override
protectes void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.mysumlayout); //set layout for mysum
int value = getIntent().getIntExtra("key",0);
check(value);
}
public void check(int x)
{
final Dialog dia = new Dialog(MySum.this);
dia.requestWindowFeature(dia.getWindow().FEATURE_NO_TITLE);
dia.setContentView(R.layout.check);
Button btn = (Button) dia.findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
int no = 12+x;
dia.dismiss();
Intent intent= getIntent();
intent.putExtra("result",no);
setResult(2,intent);
finish();
}
});
dia.show();
}
}
Note:
Apart from the above code which is just an example you need not have a Activity at all. All you do is some calculation on a int value which does not require a ui. It could be a normal java class which does just some operation without dialog or any other ui stuff.
I am integrating the zxing scanner into my android application and I am coming across a weird situation where the onActivityResult (in the activity initiating the scan) is being called before the scanning intent opens. I have looked at several examples and my code seems to match what I am seeing in many of the tutorials. Here is the code for the activity.
package com.honeydewit;
import java.util.ArrayList;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import com.honeydewit.adapters.ListItemAdapter;
import com.honeydewit.listeners.OneOffClickListener;
import com.honeydewit.pojos.BasicList;
import com.honeydewit.pojos.ListItem;
public class ListHomeActivity extends BasicActivity{
private ImageButton addItemBtn;
private ImageButton addByScanBtn;
private ArrayList<ListItem> lists = new ArrayList<ListItem>();
public static ListItemAdapter listAdapter;
private TextView headerTxt;
private BasicList basicList;
private ListView listView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listshome);
listView =(ListView) findViewById(R.id.list);
basicList = getApplicationContext().getCurrentList();
headerTxt = (TextView)findViewById(R.id.headerTxt);
headerTxt.setText(basicList.getName());
headerTxt.setTypeface(getApplicationContext().getTypeface());
//add button
addItemBtn = (ImageButton)findViewById(R.id.add);
addItemBtn.setOnClickListener(new OneOffClickListener() {
#Override
public void onClick(View v) {
addToList(v, basicList);
}
});
addByScanBtn = (ImageButton)findViewById(R.id.addByScan);
addByScanBtn.setVisibility(View.VISIBLE);
addByScanBtn.setOnClickListener(new OneOffClickListener() {
#Override
public void onClick(View v) {
addToListByScan(v, basicList);
}
});
setupListAdapter(basicList.get_id());
}
private void setupListAdapter(int listId) {
populateListItems(listId);
listAdapter = new ListItemAdapter(this, R.layout.listrow, lists);
listView.setAdapter(listAdapter);
}
private void populateListItems(int listId) {
ArrayList<ListItem> items = (ArrayList<ListItem>)getApplicationContext().getShoppingListDbHelper().getShoppingListItems(listId);
for(ListItem item : items ) {
lists.add(item);
}
}
private void addToList(View view, BasicList list) {
if(basicList.getListTypeId() == Constants.TODO_LIST_TYPE_CDE) {
Intent newListIntent = new Intent(getBaseContext(), ToDoItemActivity.class);
startActivityForResult(newListIntent, 1);
}
else {
Intent newListIntent = new Intent(getBaseContext(), ItemActivity.class);
startActivityForResult(newListIntent, 1);
}
}
private void addToListByScan(View view, BasicList list) {
try {
IntentIntegrator zxingIntegrator = new IntentIntegrator(this);
zxingIntegrator.initiateScan();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "ERROR:" + e, 1).show();
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
Log.d(getClass().getName(), scanResult.getContents());
Log.d(getClass().getName(), scanResult.getFormatName());
Log.d(getClass().getName(),data.getStringExtra("SCAN_RESULT_FORMAT"));
Log.d(getClass().getName(),data.getStringExtra("SCAN_RESULT"));
}
}
}
}
onActivityResult is called by Android whenever your app needs to be told about an Intent. That could be from lots of places. You know by looking at the request code and comparing it to the one in IntentIntegrator. Or let that class do all this for you.
My guess is your intent-filter is too broad and you're hearing things you don't expect.
I'm having some issue with zxing onActivityResult().
As you can see in the code I did properly invoke new intent as described in https://code.google.com/p/zxing/wiki/ScanningViaIntent.
The question is how can I catch onActivityResult() in Fragment, since I need this data in my Fragmnet and not in Activity?
package com.example.testingcodereading;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
public class MainFragment extends Fragment {
private Button mButtonXZing;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState){
View v = inflater.inflate(R.layout.fragment_main, parent, false);
mButtonXZing = (Button) v.findViewById(R.id.button_xzing);
mButtonXZing.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
IntentIntegrator integrator = new IntentIntegrator(getActivity());
integrator.initiateScan();
}
});
return v;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
System.out.println("never here");
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null) {
// handle scan result
}
// else continue with any other code you need in the method
}
}
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fm = getSupportFragmentManager();
Fragment f = fm.findFragmentById(R.id.fragmentContainer);
if(f == null){
f = new MainFragment();
fm.beginTransaction()
.add(R.id.fragmentContainer, f)
.commit();
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
System.out.println("the code is catch");
}
}
As Martynnw pointed out the issue is to call fragment.startActivityForResult instead of activity.startActivityForResult. So just use next wrapper:
import android.content.Intent;
import android.support.v4.app.Fragment;
import com.google.zxing.integration.android.IntentIntegrator;
public final class FragmentIntentIntegrator extends IntentIntegrator {
private final Fragment fragment;
public FragmentIntentIntegrator(Fragment fragment) {
super(fragment.getActivity());
this.fragment = fragment;
}
#Override
protected void startActivityForResult(Intent intent, int code) {
fragment.startActivityForResult(intent, code);
}
}
integrator.initiateScan();
Change the above line as
integrator.forSupportFragment(fragment_name.this).initiateScan();
Alternative ZXing Android Embedded, implementation:
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new IntentIntegrator(this).initiateScan(); // `this` is the current Activity
}
Use from a Fragment:
IntentIntegrator.forFragment(this).initiateScan(); // `this` is the current Fragment
// If you're using the support library, use:
// IntentIntegrator.forSupportFragment(this) instead.
Get the results:
#Override
public void onActivityResult(int requestCode, int resultCode,Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null) {
if(result.getContents() == null) {
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
more info and options
If any one have the same issue here is my solution.
package com.example.testingcodereading;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragment);
FragmentManager fm = getSupportFragmentManager();
Fragment f = fm.findFragmentById(R.id.fragmentContainer);
if (f == null) {
f = MainFragment.newInstance("Start Application");
fm.beginTransaction().add(R.id.fragmentContainer, f).commit();
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
System.out.println("the code is catch");
IntentResult scanResult = IntentIntegrator.parseActivityResult(
requestCode, resultCode, intent);
// handle scan result
if (scanResult != null) {
FragmentManager fm = getSupportFragmentManager();
Fragment newFrame = MainFragment.newInstance(scanResult.toString());
fm.beginTransaction().replace(R.id.fragmentContainer, newFrame).commit();
}
}
}
package com.example.testingcodereading;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.test.suitebuilder.annotation.MediumTest;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
public class MainFragment extends Fragment {
private static final String EXTRA_CODE = "com.example.testingcodereading.code";
private Button mButtonXZing;
private TextView mTextView;
public static MainFragment newInstance(String code) {
Bundle args = new Bundle();
args.putSerializable(EXTRA_CODE, code);
MainFragment fragment = new MainFragment();
fragment.setArguments(args);
return fragment;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState){
View v = inflater.inflate(R.layout.fragment_main, parent, false);
mTextView = (TextView) v.findViewById(R.id.text_code);
mTextView.setText((String) getArguments().getSerializable(EXTRA_CODE));
mButtonXZing = (Button) v.findViewById(R.id.button_xzing);
mButtonXZing.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
IntentIntegrator integrator = new IntentIntegrator(getActivity());
integrator.initiateScan();
}
});
return v;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
System.out.println("never here");
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null) {
// handle scan result
}
// else continue with any other code you need in the method
}
}
I had this problem and resolved it with below codes:
IntentIntegrator integrator = new IntentIntegrator(getActivity());
integrator.forSupportFragment(MyFragment.this).initiateScan();
Shall call the scan in this way:
IntentIntegrator.forSupportFragment(YourFragment.this)
.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE)
.setBeepEnabled(true/false)
.setPrompt("blahblahblah")
.initiateScan();
Then you can get the scan result in Fragment's onActivityResult
Make sure OnActivityResult in your Activity is calling super.OnActivityResult(). That should ensure it's called on the Fragment as well.
Alternatively, you could modify the IntentIntegrator code so it calls StartActivityResult on the Fragment, either by passing the fragment to the constructor, or passing it to initiateScan.
Try creating IntentIntegrator object in Fragment as below.
val scanIntegrator = IntentIntegrator.forSupportFragment(this#HomeFragment)
scanIntegrator.setPrompt("Scan")
scanIntegrator.setBeepEnabled(true)
//The following line if you want QR code
scanIntegrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES)
scanIntegrator.captureActivity = CaptureActivityAnyOrientation::class.java
scanIntegrator.setOrientationLocked(true)
scanIntegrator.setBarcodeImageEnabled(true)
scanIntegrator.initiateScan()
public void scanCode() {
IntentIntegrator.forSupportFragment(this).
setCaptureActivity(CaptureAct.class).
setOrientationLocked(false)
.setDesiredBarcodeFormats(IntentIntegrator.PRODUCT_CODE_TYPES)
.setPrompt("Scanning code")
.initiateScan();
}
A solution : A basic example of how you can manage it
Main Activity
public static int tapTrick = 0;
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//super.onActivityResult(requestCode, resultCode, data);
if(tapTrick!=0 && tapTrick==1) {
Tab1.onActivityResult(requestCode, resultCode, data, MainActivity.this);
}else if (tapTrick!=0 && tapTrick==2){
//Tab2.onActivityResult(requestCode, resultCode, data, MainActivity.this);
}
}
Fragment 1
MainActivity.tapTrick=1; // onCreateView or onClick (load images/files)
public static void onActivityResult(int requestCode, int resultCode, Intent intent, Context context) {
}
Fragment 2
MainActivity.tapTrick=2;
public static void onActivityResult(int requestCode, int resultCode, Intent intent, Context context) {
}
Fragment x
MainActivity.tapTrick=x;
public static void onActivityResult(int requestCode, int resultCode, Intent intent, Context context) {
}