Can anyone please correct my approach or suggest me the right ways for doing it.I have tried using broadcast receivers in place of services but that approach is not working for it.i.e I used getBroadcast() in place of getService() but didnt work.
It is working when the app is not closed from the application window but as soon as it is closed , the phone doesnt show notifications and ring as it was working in the case when the app wasn't closed.
MainActivity.class
`public class MainActivity extends AppCompatActivity {
TimePicker timePicker;
Button button;
AlarmManager alarmManager;
PendingIntent alarmIntent;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
timePicker = findViewById(R.id.timePicker);
button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Calendar calendar = Calendar.getInstance();
if (Build.VERSION.SDK_INT >= 23) {
calendar.set(
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH),
timePicker.getHour(),
timePicker.getMinute(),
0
);
} else {
calendar.set(
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH),
timePicker.getCurrentHour(),
timePicker.getCurrentMinute(),
0
);
}
Intent intent = new Intent(MainActivity.this,MyIntentService.class);
//This is the intent which will be fired
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmIntent = PendingIntent.getService(getApplicationContext(), 0, intent, 0);
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent);
Log.e("TAG:","AlarmSet.");
// Log is showing the right statement i.e the alarm was set but it wasnt triggered when the app was closed from the application window
}
});
}
#Override
protected void onStart() {
super.onStart();
}
#Override
protected void onPause() {
super.onPause();
Log.e("TAG","OnPause.");
}
#Override
protected void onStop() {
super.onStop();
Log.e("TAG","OnStop.");
}
#Override
protected void onDestroy() {
super.onDestroy();
Log.e("TAG","OnDestroy.");
}
}`
IntentService.class
`public class MyIntentService extends IntentService {
public MyIntentService() {
super("MyIntentService");
}
#Override
protected void onHandleIntent(#Nullable Intent intent) {
Log.e("TAG", "Starting service for notification and song");
Random random = new Random();
final Notification notification = new NotificationCompat.Builder(getApplicationContext(), "notify")
.setContentTitle("New Notification")
.setContentText("TIme for task.")
.setSmallIcon(R.mipmap.ic_launcher_round)
.setPriority(Notification.PRIORITY_MAX)
.build();
final NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(random.nextInt(), notification);
MediaPlayer mediaPlayer = MediaPlayer.create(getApplicationContext(), Settings.System.DEFAULT_RINGTONE_URI);
mediaPlayer.start();
}
}`
Manifest file
`
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MyIntentService"
android:enabled="true"
android:exported="true" />
</application>
</manifest>`
Related
I am attempting to create a more complex app but was unable to correctly use AlarmManager to open an activity. I tried distilling the code down just to the essence of what I'm missing is, but it still is not working correctly.
The app basically just accepts a minute and hour input along with a start button, and is supposed to open the second activity when the time is inputted. However, the second activity never opens at the time I enter, and nothing in LogCat seems to change. Here is my current code:
MANIFEST:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.goali.adalarm">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".AlarmReceiver2" >
<intent-filter>
<action android:name="android.intent.alarmclock.ALARM_ALERT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<activity android:name=".AlarmReceiver">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity:
public class MainActivity extends AppCompatActivity {
Calendar c;
PendingIntent pendingIntent;
AlarmManager alarmManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
c = Calendar.getInstance();
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
final EditText hour = (EditText) findViewById(R.id.hour);
final EditText minute = (EditText) findViewById(R.id.minute);
Button button = (Button) findViewById(R.id.press);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
c.set(Calendar.HOUR_OF_DAY, (Integer.parseInt(hour.getText().toString())));
c.set(Calendar.MINUTE, Integer.parseInt(minute.getText().toString()));
c.set(Calendar.SECOND,0);
c.set(Calendar.MILLISECOND,0);
Intent intent = new Intent(MainActivity.this, AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pendingIntent);
}
Toast.makeText(MainActivity.this, "Alarm Set.", LENGTH_LONG).show();
}
});
}
}
2nd activity:
public class AlarmReceiver extends AppCompatActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alarm_receiver);
}
}
BroadcastReceiver:
public class AlarmReceiver2 extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent intent2 = new Intent(context, AlarmReceiver.class);
Toast.makeText(context, "Alarm worked.", Toast.LENGTH_LONG).show();
context.startActivity(intent2);
}
}
From you code I guess you want to start an Activity or a Broadcast after amounts of time from now by using AlarmManager.
To start an activity (AlarmReceiver).
public class MainActivity extends AppCompatActivity {
PendingIntent pendingIntent;
AlarmManager alarmManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
final EditText hour = (EditText) findViewById(R.id.hour);
final EditText minute = (EditText) findViewById(R.id.minute);
Button button = (Button) findViewById(R.id.press);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int hours = Integer.parseInt(hour.getText().toString());
int minutes = Integer.parseInt(minute.getText().toString());
Intent intent = new Intent(MainActivity.this, AlarmReceiver.class);
pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
// 1 hour = 60 minutes = 3600 seconds = 3600000 milliseconds.
long timeFromNowInMilliseconds = (hours * 3600000) + (minutes * 60000);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeFromNowInMilliseconds, pendingIntent);
}
Toast.makeText(MainActivity.this, "Alarm Set.", LENGTH_LONG).show();
}
});
}
}
To start a broadcast (AlarmReceiver2)
public class MainActivity extends AppCompatActivity {
PendingIntent pendingIntent;
AlarmManager alarmManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
final EditText hour = (EditText) findViewById(R.id.hour);
final EditText minute = (EditText) findViewById(R.id.minute);
Button button = (Button) findViewById(R.id.press);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int hours = Integer.parseInt(hour.getText().toString());
int minutes = Integer.parseInt(minute.getText().toString());
Intent intent = new Intent(MainActivity.this, AlarmReceiver2.class);
pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0);
// 1 hour = 60 minutes = 3600 seconds = 3600000 milliseconds.
long timeFromNowInMilliseconds = (hours * 3600000) + (minutes * 60000);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeFromNowInMilliseconds, pendingIntent);
}
Toast.makeText(MainActivity.this, "Alarm Set.", LENGTH_LONG).show();
}
});
}
}
I want to make a alarm clock in android and I write this with BroadcastReceiver But I have some problem with that...
I want to start alarm in specified time for example I want start alarm in every 3:50...
but when I am running the App alarming starting too...
There is my code bellow:
Any one could help me:
there is my broadcast Receiver:
public class MyBroadcastReceiver extends BroadcastReceiver {
public static MediaPlayer mediaPlayer;
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("com.tester.alarmmanager")) {
Toast.makeText(context, "Its time!!!", Toast.LENGTH_SHORT).show();
mediaPlayer = MediaPlayer.create(context, R.raw.entezar);
mediaPlayer.start();
}
}
}
And in MainActivity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StartAlarm(03,50);
}
public void StartAlarm(int hour, int min){
Intent intent = new Intent(this, MyBroadcastReceiver.class);
intent.setAction("com.tester.alarmmanager");
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(),23433,intent,0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
Log.v("time picker",calendar.getTime()+"");
calendar.set(Calendar.HOUR_OF_DAY,hour);
calendar.set(Calendar.MINUTE,min);
calendar.set(Calendar.SECOND,00);
if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.KITKAT){
alarmManager.setExact(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),pendingIntent);
Toast.makeText(MainActivity.this, "Alarm>kitkat", Toast.LENGTH_SHORT).show();
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT){
alarmManager.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),pendingIntent);
Toast.makeText(MainActivity.this, "Alarm<kitkat", Toast.LENGTH_SHORT).show();
}
}
And in Manifest:
<receiver android:name=".Utility.MyBroadcastReceiver">
<intent-filter>
<action android:name="com.tester.alarmmanager"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
add after calendar.getInstance()
calendar.setTimeInMillis(System.currentTimeMillis())
or check code under this link https://github.com/mrkostua/SmartAlarm/blob/master/app/src/main/java/com/mrkostua/mathalarm/alarms/mathAlarm/AlarmManagerHelper.kt
I am working on an App in which i want to set custom alarm.but after setting a time on alarm nothing happens. i am sharing my code. Please help and guide me if something is missing in my code.
In my MainActivity.java
#Override
protected Dialog onCreateDialog(int id) {
if (id == DIALOG_ID) {
return new TimePickerDialog(MainActivity.this, kTimePickerListener, hour, min, false);
}
return null;
}
protected TimePickerDialog.OnTimeSetListener kTimePickerListener =
new TimePickerDialog.OnTimeSetListener() {
#Override
public void onTimeSet(TimePicker timePicker, int hourofday, int minutes) {
hour = hourofday;
min = minutes;
Calendar calendar = Calendar.getInstance();
// set selected time from timepicker to calendar
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minutes);
Intent myIntent = new Intent(MainActivity.this, ServiceManager.class);
myIntent.putExtra("reqcode", 11);
// A PendingIntent specifies an action to take in the
// future
PendingIntent mPendingIntent = PendingIntent.getBroadcast(MainActivity.this, 11, myIntent, 0);
// set alarm time
alarmManager = (AlarmManager) MainActivity.this
.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), mPendingIntent);
}
};
In My ServiceManager.class
public class ServiceManager extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
int Noti_code = intent.getIntExtra("reqcode",-1);
Intent myIntent = new Intent(context, NotificationService.class);
myIntent.putExtra("reqcode", Noti_code);
context.startService(myIntent);
}
}
In My NotificationService.class
public class NotificationService extends Service {
private NotificationManager mManager;
#Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public void onCreate() {
super.onCreate();
}
#SuppressWarnings({"static-access", "deprecation"})
#Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
int Noti_Code = intent.getIntExtra("reqcode",-2);
if (Noti_Code == 11) {
mManager = (NotificationManager) this.getApplicationContext().getSystemService(this.getApplicationContext().NOTIFICATION_SERVICE);
ShowNotification(getApplicationContext(), mManager);
}
}
#Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
}
In my Manifest.xml
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity_detail" />
<activity android:name=".History" />
<service
android:name=".NotificationService"
android:enabled="true"
android:exported="true"
android:stopWithTask="false"/>
<receiver android:name=".ServiceManager"
android:process=":remote"/>
</application>
I am checking through debugging broadcast receiver doesn't called. Please help me if i am missing any thing.
Also i want to know how many pending intent can be fire at a time and will all works one by one?
Thanks.
Refrence links:
AlarmManager wont fire pending intent
http://code4reference.com/2012/07/tutorial-on-android-alarmmanager/
BroadcastReceiver and AlarmManager not working with
AlarmManager is not working after app is closed? - Android
You have your BroadcastReceiver running in another process. If you are setting breakpoints with a debugger you will miss this. If you don't need your BroadcastReceiver running in a separate process, remove the
android:process=":remote"
declaration from the manifest.
See the documentation about how the android:process specifier works.
I have created a receiver that Extends BroadcastReceiver. This is used to execute my Notification that repeats daily, based on the time selected by the user. For some reason i cant get this to work. I am worried that i am getting the time from the number pickers wrong, but i am new to programing and could use some help. Thank you in advance. Let me know if you see any Errors.
Here is my main activity (MyActivity)
public class MyActivity extends Activity {
TimePicker timePicker;
Button setAlarm;
private int hour;
private int minute;
PendingIntent pendingIntent;
int AM_PM;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
timePicker = (TimePicker) findViewById(R.id.timePicker);
setAlarm = (Button) findViewById(R.id.setUpAlarm);
setAlarm.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
setAlarm();
}
});
}
private void setAlarm() {
int hour = timePicker.getCurrentHour();
int minute = timePicker.getCurrentMinute();
long time = 60 * hour + minute;
AlarmManager alarmMgr = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent intent = new Intent(this, NotifyService.class);
PendingIntent alarmIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
//create alarms
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
// AlarmManager.INTERVAL_DAY.
alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, alarmIntent);
}
Here is my Notification class ( extends BroadcatsReceiver )
public class NotifyService extends BroadcastReceiver {
public NotifyService() {
}
#Override
public void onReceive(Context context, Intent intent) {
//generate notification // should be splash activity
PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(context, MyActivity.class), 0);
Notification notification = new NotificationCompat.Builder(context)
.setContentTitle(null)
.setContentText("Your tip for today is ready")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pi)
.build();
}
// dont forget to compile "com.android.support:support-v4:18.0.+"
}
Here is my manifest
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MyActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".NotifyService"
android:enabled="true"
android:exported="true" >
</receiver>
</application>
Dont use a receiver with a filter in your android manifest. Create an 'explicit intent' instead of using an intent filter. This way,
Intent i = new Intent(your random intent Action name).
This should fix you problem
In my app, users have to fill in 9 different times with timepickers. These times are stored in a SQLite database. I want that users get a status bar notification when one of the times has been reached.
Example:
Users fill the first time in at 09:00.
If it is 09:00 in real time, users need to get a statusbar notification. I want that they don't need to start the app, it has to be automatic.
After spending more then 4 hours today at stackoverflow and other websites, I didn't succeed. I have tried the following code, but I didn't succeed. The notification is now set to 12:00. When the time reached 12:00, I didn't get a message.
MainActivity:
public class MainActivity extends Activity {
AlarmManager am;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent alarmIntent = new Intent(this, TimeAlarm.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 12);
calendar.set(Calendar.MINUTE, 00);
calendar.set(Calendar.SECOND, 00);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 5000, pendingIntent); } }
TimeAlarm.class:
public class TimeAlarm extends BroadcastReceiver {
NotificationManager nm;
#Override
public void onReceive(Context context, Intent intent) {
Intent startServiceIntent = new Intent(context, NotificationService.class);
context.startService(startServiceIntent);
}
}
NotificationService.class:
public class NotificationService extends Service {
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
handleIntent(intent);
return START_NOT_STICKY;
}
private NotificationManager nm;
private WakeLock mWakeLock;
#Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
#Override
public void onDestroy() {
super.onDestroy();
mWakeLock.release();
}
private void showNotification() {
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Test")
.setContentText("Test message");
Intent resultIntent = new Intent(this, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
private class PollTask extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... params) {
showNotification();
return null;
}
#Override
protected void onPostExecute(Void result) {
stopSelf();
}
}
private void handleIntent(Intent intent) {
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"NotificationsService");
mWakeLock.acquire();
ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
if (!cm.getBackgroundDataSetting()) {
stopSelf();
return;
}
new PollTask().execute();
}
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission
android:name="com.test.app.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- This app has permission to register and receive data message. -->
<uses-permission
android:name="com.google.android.c2dm.permission.RECEIVE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
<activity
android:name="com.test.app.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.test.app.TimeAlarm">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
Try changing START_NOT_STICKY to START_STICKY;. If your service isn't sticky android does not try to restart it if it has to be killed to make room for other apps in memory.