0

I have two activities.( activity 1 and activity 2) activity 1 has a public Array like this

 public byte[][] arrtest=new byte[3][1024];

I call activity 2 and I want to get value from arrtest in activity 2.

How can I do this?

Samet ÖZTOPRAK
  • 3,112
  • 3
  • 32
  • 33
Fatemeh
  • 177
  • 15
  • 1
    You can pass it in intent. – WritingForAnroid Nov 07 '16 at 04:59
  • pass arrtest array through intent – Pavya Nov 07 '16 at 04:59
  • 2
    Pass it in bundle or intent OR declare it as static and then use it anywhere – Vickyexpert Nov 07 '16 at 05:00
  • Intent won't work if size is too large. Save it somewhere. And then just pass the path to another `Activity` – Jimit Patel Nov 07 '16 at 05:01
  • use shared preferences – Deepak Kumar Nov 07 '16 at 05:05
  • I'm new in android. please give me a code. I defined it as static . but when I wrote activity1.arrtest is undefined in activiy2. – Fatemeh Nov 07 '16 at 05:10
  • (for pass arrtest through intent. ) activity2 wants call activity1 and get value. but I think intent is for pass value to activity1 – Fatemeh Nov 07 '16 at 05:12
  • Thank you veru much. I defined it static and now I can see it in activity2 – Fatemeh Nov 07 '16 at 05:14
  • @Fatemah store your byte array into a file. You can use this code from here http://stackoverflow.com/a/6828668/842607 and then send the file path to another `Activity`. You can check comments from http://stackoverflow.com/a/31426584/842607 for what kind of error you can get. So store it in device then send the file path to another activity. Retrieve byte array from using file path and do your proceeding stuffs – Jimit Patel Nov 07 '16 at 05:38

2 Answers2

0

Pass array to another acivity and then use it.Check out this answer

https://stackoverflow.com/a/7257726/3789993

Community
  • 1
  • 1
AbhayBohra
  • 2,047
  • 24
  • 36
0

You have to use bundle or adding it into intent.

    Intent intent = new Intent(view.getContext(), ApplicationActivity.class);
                        intent.putExtra("key", value);
                        startActivity(intent);

invoked activity.

Intent intent = getIntent();
Bundle bundle = intent.getExtras();

if(bundle != null){
    mealId = bundle.getInt("key");
}
Samet ÖZTOPRAK
  • 3,112
  • 3
  • 32
  • 33