Capture Android App Launch and App Minimize events - android

I have to do capture Applaunch and App minimize events for myapp for Appirater integration. I have to show Appirater dialog for every 3rd app launch/app minimize
I followed the article
http://vardhan-justlikethat.blogspot.in/2013/05/android-solution-to-detect-when-android.html
But i have a problem, i have many activities,fragments in Application.say some Activities extends FragmentActivity, some of the them are fragments and some of them extends Activity
But, as per the article, i have to extend all the activities using Base Activity
It implies the architecture changes for my application.
If i write the code separate for each activities, the Appirater wonk work proper. Any alternatives to this ? please help in fixing
Tried also by extending Application class but it can capture app minimze events

Create a BaseActivity And a BaseFragmentActivity that does the same as the BaseActivity in the example, and then extend them in the appropriate places, should still work the same and you don't have to do much work. Correct me if I'm wrong, I just skimmed through it
Edit, example:
public class BaseActivity extends Activity{
//everything
}
and the other
public class BaseFragmentActivity extends FragmentActivity{
//everything
}

Related

what does getConfirmationTts() in voice interaction do

the clip of the code written for using voice interaction which is used in another Java file I have already tried importing android.app.VoiceInteractor but its not working
You may have imported all necessary classes in your code. As your snippet you forgot to extend that, But you are already extending AppCompatActivity so that you can't extend another class in the same Activity. What you need to do is create another class inside MyVoiceActivity and extend VoiceInteractor.ConfirmationRequest in that class.
Your Activity will look something like this
public class MyVoiceActivity extends AppCompatActivity{
class Confirm extends VoiceInteractor.ConfirmationRequest {
//All method you wanted goes here
}
}

Android Root of all Activities and Fragments

How can I implement "dispatchTouchEvent(...){}" on root of my android app instead of each of activities, because I want to get when my application get sleep or in pause state.
You could create a BaseActivity where you implement it and all your activities inherit from BaseActivity:
class BaseActivity extends AppCompatActivity {
dispatchTouchEvent() {...}
}
class MyActivity extends BaseActivity {
...
}
This kind of central handling would be possible if all your activities are extended from single activity in your project. Say, AppBaseActivity contains most general functionality & all others extend it. So, events can be traced down to this AppBaseActivity. I can't predict any other way to achieve the result you want to get.

Android Class Diagram UML

I'm trying to create a class diagram for an android project.
I want my classes represent the activities, services and interfaces that I will implement.
There are several questions about it on the web, but I couldn't find a definitive answer.
I know that there aren't specific rules for Android and UML, but I have some doubts.
How can I represent the relationship between an Activity and a AsyncTask ?
How can I indicate that an Activity has an intent to another Activity ?
Maybe if someone has an example, will really help.
Maybe something like this?
MyBackgroundTask IS A AsyncTask
MyActivity IS A Activity
MyActivity HAS ONE MyBackgroundTask
You can use a dependency to show that there is an relationship between the AnActivity class and the AnotherActivity class:
In this case, it means that the AnActivity class requires the AnotherActivity class for its specification or implementation. Also, use notes to make it clear.
Update:
Another example:
MainActivity IS A FragmentActivity
MainActivity HAS SOME fragments. The fragments are of type String.

Adding functionality to the activity (inheritance, decoration, strategy ... )

I cannot decide what approach should I use in the next situtation.
One activity from my app need to have different functionality, here is the leak of multiple inheritence comes into play.
What I need to get ?
There are several parts that my activity has to have.
Navigation drawer. I am using MaterialDrawer library. It requires activity to implement on click callbacks (or use composition instead), but also it use activity as constructor argument,so I think it will be better to put this into separate class inherited from Activity or any base class provided by Android Framework . Thanks to library developer it doesn't require any stuff to be done in on create method ( setContentLayout for instance)
My activity(one of several) will have only Toolbar and FrameLayout for holding fragment . Or it is better to separate toolbar and single fragment ?
This in turn requires some stuff to be done in onCreate : setContentLayout with basic layout , add fragment to the container set activity actionbar .....
Maybe in future I will use another libraries that requires to add something in activity lifecycle methods.
All these points in order to follow Single Responsibility principle have to be separate classes inherited from some base Activity.
For example we will have something like this.
public class SingleFragmentActivity<T extends Fragment> extends AppCompatActivity {
}
public class SingleFragmentToolbarActivity<T extends Fragment> extends AppCompatActivity {
}
public class NavigationDrawerActivity extends AppCompatActivity {
}
....
As you can see each functionality is put into the separate class, but what if I need to have SingleFramgentActivity with NavigationDrawer ?
In this case I have to inherit one of these classes from another, for example
public class NavigationDrawer extends SingleFragmentActivity {
}
If to do so, I have no ability to use navigation drawer separately from SingleFragmentActivity.
What is the best practice to follow in this case, how to build class hierarchy to make it flexible and use Open-Close principle, to make changes in application without any pain. (Use strategy, decorator ..... ?)
I would be grateful everyone for help.

How to use multilevel inheritance in android

I am making an app in which i have to run an activity in background until the app is running.each activity related to this app is using first activity.how can it possible?
can i use the inheritance for this?
can anyone tell me any example of multilevel interitance in android?
You can create a BaseActivity class that extends Activity and all other Activities will extend this BaseActivity. Then what ever happened in all other activities (like resume and pause) will also effect the actions of BaseActivity.
If you have to accomplish background task you better to see android service
You are already extending the Activity class in a base class, and again you are extending this base class in other class. This is itself an example of multilevel inheritance. I am posting an example that may be relevant for your question:
public class basecls extends Activity{
/*The base class*/
}
public class secondcls extends basecls{
/* basecls extended by secondcls */
}
You can extend the secondcls in another class, and the new class will inherit all super classes such that you can use the methods of its super classes.
Your main activity is already using inheritance, since it extends the Activity class.

Categories

Resources