Friday, 15 May 2015

Android: How to start an activity from a non-activity class using a single instance -


I have a Java class (no activity) and I want to start a new activity from him. I am getting the reference of the app on my initialization and then I am using it to start a new activity as shown below. However, the code only if I add the following part of the code to the intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK) code, then it only works, which is not what I want because I only want an example of every activity I am How can I do this, but instead of creating a new activity already created? My code is:

  Public square fu {... protected Foo (reference reference) {applicationContext = context; } Private Zero ButtonClick () {intention intended = new intent (applicationContext, Bar.class); Intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK); / / That line does not work without the app. launch. Initiality (intent); }}  

In that situation, you should use the activity reference to start a new activity Will happen. You should modify the class like below

  public square fu {... protected Foo (activity activity context) {this.activityContext = activityContext; } Click on Personal Zero button () {intention intended = new intention (promotion of activity, bar class); ActivityContext.startActivity; }}  

But here you are not cleaned the code idea, where you are using this class. Because you have made this method private


No comments:

Post a Comment