As to your question, one way could be via your orchestration logic (your workflow code)
You can catch ActivityFailure for activity 2 (you should btw do error handling for any of your activity invocations) which is delivered to your workflow code after all activity retries are exhausted, and then can decide to invoke activity 1 again if you wanted.
If you need to retry a sequence of activities together, you can use workflow-level retries via `Workflow.retry, see sample here.