-1

Is there a way to pass color of view or button between activity and another?

"the user who will Choose Color"

I tried a lot and every time I run it, I get the message:"unfortunately app has stopped"! when i open activity2

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
Ola Adel
  • 1
  • 3
  • 3
    [Use LogCat](https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this) to examine the Java stack trace associated with your crash. If you want help with your existing approach, please edit your question to have a [mcve], and explain in greater detail what "color of view" means. – CommonsWare Feb 27 '16 at 15:36

2 Answers2

0

Do this....

  1. get the id of the selcted color
  2. pass that color to the activity2
  3. load that color from resources

Activity 1

 Intent pass = new Intent( );
 Bundle extras = new Bundle();
 extras.putInt("colorResourceName", colorResourceName);
 pass.putExtras(extras);
 startActivity(pass);

Activity 2

public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     Bundle data = getIntent().getExtras();
     int colorResourceName = data.getIntExtra("colorResourceName", -1);

}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
0

Following Xoce's response, you can also do something like this if you don't have the color defined as a resource or somehow just know it's hex code:

Activity 1

Intent pass = new Intent( );
Bundle extras = new Bundle();
extras.putInt("colorHexCode", colorHexCode); //Example of color code: "#FFFFFF"
pass.putExtras(extras);
startActivity(pass);

Activity 2

public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 Bundle data = getIntent().getExtras();
 String colorHexCode = data.getStringExtra("colorHexCode");
 TextView textView = (TextView) findViewById(R.id.my_text_view);
 textView.setTextColor(Color.parseColor(colorHexCode));
}