I want to create an activity monitor program which monitors activities and their events as specified.
Can you please tell me how can I know which event in a running activity is being executed? How can I collect data related to clicks or swipes in the same activity i.e. which button or menu is being clicked.
You can get the running activity name by using-
this.getClass().getSimpleName()
I used above code many times to find running activity name in my App.
Try below code to find the pressed button information,
public void onClick(View view) {
Button b1 = (Button)view;
String text = b1.getText().toString();
}
Related
I have a question. How can I put two or more buttons on the MainActivity and have it go to the SecondActivity? All the SecondActivities are going to be different.
Drag and drop a button using android studio. once the button had been placed within the layout. In properties palette you will be able to find something called onClick. which means the action to be performed once the button click occurs, give a name for the onClick method eg: add
public void add (View v){
Intent intent = new Intent(MainActivity.this,displayActivity.class);
startActivity(intent);
}
displayActivity is the name of your second Activity. once the button had been clicked you will be directed to the secondActivity.The same step can be followed for the next button.
So I have a button with a onClick method like this:
public void myClickHandler(View v){
}
I have multiple checkboxes on one page, and when that button is pressed it will start a timer on all of the checked boxes. Also, most of the timers have different times. Have any ideas on how I can get this working? Thanks!
i think,you can use one timer,or just one thread.computing and send different broadcasts or the same broadcast with different args,handle and dispatch in the method onReceive;
While developing an android app, I have an activity with some buttons. I would like the onClickListener action to start when the user puts his finger on the screen immediately so he isn't able to click two buttons at once.
I do that in iOS by using the touchDown event rather than the default TouchUpInside.
I have absolutely no idea of how this can be done in Android...
Android code :
button.setOnClickListener(clicked);
[...]
View.OnClickListener clicked = new View.OnClickListener() {
public void onClick(View v) {
//Cool stuff there
}
}
thanks for helping !
What you are looking for is using an OnTouchListener instead of the OnClickListener. This will allow you to react upon the first touch of the button and stop reacting on other button touches until the first touch is stopped again.
You can disable the other buttons when you start the click and re-enable them when you are finished.
By default the buttons clicks will be handled on the same thread so their actions would not complete in parallel even if you do not disable them.
I am creating an app which consists of main, register, option activities. Main and register activities should be started only once. I got it. Problem is they are again appearing when I just going back to my mobile home page without clicking exit. Even if I do not click the exit and goes back to home, they should not appear again when I entered!! Is this possible? I am not able to get the solution for this. Any one please help me.. Thankyou
you can override the method onStop() and put finish() there.
So, when the activity will be not longer visible, it will finish. Or you can put finish() after startActivity() call method.
you can do this by.
Button button15 =(Button)findViewById(R.id.button5);
button15.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
finish();
}
}
);
I am developing media player application in which i am showing a notification when song starts playing in a service.
Basically i am showing a list view in my first activity(being any one from Artist tab, album tab etc) and on click of an item , player screen is shown.
I have to implement a back button in my player activity, i guess i just have to do a finish() on click of it.
But in case my previous activity is destroyed and i am coming through pending intent(through notification), if i call finish() now the activity is simply destroyed. In such case i want to recreate the previous activity.
Example :
Album > player screen is shown and songs starts in service with status bar notification..
Suppose i press back now and destroy all the activity.
Click on notification > Player is shown again.. if i press back now Album activity should be shown similarly for artist tab.
So far i am just doing:
btnBack.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
I guess you can achieve what you need with setting the intent flags accordingly. The best introduction to these flags I found is the following
Android Activities and Tasks series – Intent flags
It is still a confusing subject for me yet the Android application offered along with this article is very helpful to check quickly what the different flags do.
I thinking you must set more informations about song in Service like a album and when you press back in song activity you should chek service and give back it from Service and init album activity