last day (15 days later) » 

6:18 AM
2
A: Finish application after 15 minutes in background

Sagar ZalaSolution: Make one BaseActivity which is parent of all of your activities. public class BaseActivity extends AppCompatActivity { private static Thread t = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Ov...

 
When I open new activity from mainActivity, onPause method runs, and exit application. I think the above code must not be work between activities
 
No, if your MainActivity pause for 15 minutes then exit otherwise not.
 
I think the above code should not be work between activities. I want to trigger when application at background
 
Have you try my code?
 
Yes. I create BaseActivity as you say. Then extend BaseActivity for all activities. But the problem was when I pass to second activity from first activity application exits after 15 min.
 
6:18 AM
Make Thread variable static like, private static Thread t = null;
For testing set sleep time = 30 seconds like sleep(30 * 1000);, so you don't have to wait for 15 minutes.
 
Sagar?
 
6:37 AM
Yes
 
I change it to static
it working but
little problem
When I return to the application after 30 seconds it stays 5 seconds and then restarted
Do you have experience with WebSockets ? Can you help me to solve this problem also? stackoverflow.com/questions/53301142/…
 
Add finish(); above System.exit(0);
try {
sleep(10 * 1000);
finish();
System.exit(0);
} catch (InterruptedException e) {
return;
}
 
ok i will try this
Thank you
well done
working nice
 
Welcome
 
Do you have experience with WebSockets ? Can you help me to solve this problem also? stackoverflow.com/questions/53301142/…
 
6:49 AM
Please upvote my answer
 
Yes I accept your answer and upvoted
 
Ok thanks.
For websocket I need to research.
 
Can you help me with the second problem ?
Ok
I am waiting answers
 
Application is crashing in web socket problem??
 
No application not crashes. I think the problem was in connectivity to the internet. When I start application web socket working. But when I restart my internet or connected to wifi web socket not working. For work I need to restart app,
 
6:57 AM
ok
send me full code by github?
 
I can't, because of some reason with confidentiality
but
import android.app.Application;

import com.neovisionaries.ws.client.WebSocket;
import com.neovisionaries.ws.client.WebSocketFactory;

import java.io.IOException;

public class App extends Application {
private static WebSocket ws = null;
WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(5000);

@Override
public void onCreate() {
super.onCreate();

try {
ws = factory.createSocket("wss://websocket/");
ws.connectAsynchronously();
} catch (Exception ignored) {
}
}
public WebSocket getSocket(){
app.java
and chat acitivity
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;

import com.neovisionaries.ws.client.WebSocket;
import com.neovisionaries.ws.client.WebSocketAdapter;
import com.neovisionaries.ws.client.WebSocketListener;
 

last day (15 days later) »