0

I have two activities for a drawing app I am making, let's call them A and B. Activity A is the canvas the user draws on, and thus will always be active so it does not lose its state. Activity B is activated when a button on A is pressed and opens a menu to change the drawing colour. I want to be able to click a button on B and have it send the colour value of the button in B to the existing A to update the colour, but haven't found any way to be able to do that.

I know it should be done in the onClick for the buttons, but other than that I don't have any clue.

Alternatively, is there a way to save the state of A somewhere and then start a new instance of A and reload it with the same drawings on it but updated drawing colour?

monke
  • 1
  • please check this previously asked question that will help in clearing your concepts. [link](https://stackoverflow.com/questions/20169993/how-to-transfer-data-from-one-activity-to-another-in-android) – Umair Qayyum Nov 11 '22 at 04:51
  • Instead of startActivity you should use startActivityForResult. Activity B then puts the chosen color in the result intent and finishes. A can then read the color from the intent. – blackapps Nov 11 '22 at 05:33
  • Do you know about handlers in android? Well you have many options: handlers, maybe callbacks, activity result, shared preferences, view models etc. It depends what kind of data you deal with. If it is an `int` type color value, it is relatively easier than handling complex object values. – Kozmotronik Nov 11 '22 at 05:49
  • How about put the data in a singleton model class and access it via Activity, Service or other utility. This is the most common way to do so in the scope of a single application. – Android Newbie A Nov 11 '22 at 06:19
  • I am sure that there will be someone mentioned that this is not so good comparing to pass an Intent from one activity to another. But I only use intent when I need to call from App A to App B. – Android Newbie A Nov 11 '22 at 06:21

0 Answers0