آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

بسته شدن سرویس

سجاد زهره ای  11 سال پیش  11 سال پیش
+1 0

سلام من یه سرویس دارم یعنی کدشو از اینترنت گرفتم ولی یه مشکل داره وقتی مثلا داخل تبلت وقتی برنامه های درحال اجرا رو میبندی دیگه سرویس هم از بین میره و دوباره باید login کنی؟بنظرتون چه چیزی کم داره که باعث این میشه؟

+1 0
ای خدااااا خداوکیل حداقل بنویسین بلد نیسم خداشاهد صدتا سوال پرسیدم هیچکس جوابم نمیده ای بابا استاد حداقل شما بگین منم وقت ندارم تا باخیال راحت بگم این انجمن جواب من نمیدن بخدا اعصابم داغون شد هرسوالی میپرسم انگار نه انگار اگه مشکل از منه خب بگین والا (11 سال پیش)
0 0
اینو خداییش قبول دارم ! نمیدونم چرا بیشتر سوالای شما یا پاسخ نگرفته یا دیر پاسخ گرفته ! آخه سوالات سخته :) (11 سال پیش)
0 0
توضیحات شما از توضیحات من گنگ تره :) ، دارم رکوردم رو می دم به تو ؛ یه سرویس داری ؟ توی Manifrst تعریف کردیبیا فقط توی کدنویسی فراخوانی می کنی ؟ (11 سال پیش)
0 0
داخل Manifrst تعریف کردم!الان کدهای سرویسم رو میزارم (11 سال پیش)
 برای این سوال 2 پاسخ وجود دارد.
پاسخ به سوال 
سجاد زهره ای  11 سال پیش
0 0

   @Override
public void onCreate()
{
mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

localstoragehandler = new LocalStorageHandler(this);

conManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
new LocalStorageHandler(this);

// Timer is used to take the friendList info every UPDATE_TIME_PERIOD;
timer = new Timer();

Thread thread = new Thread()
{
@Override
public void run() {

//socketOperator.startListening(LISTENING_PORT_NO);
Random random = new Random();
int tryCount = 0;
while (socketOperator.startListening(10000 + random.nextInt(20000)) == 0 )
{
tryCount++;
if (tryCount > 10)
{
// if it can't listen a port after trying 10 times, give up...
break;
}

}
}
};
thread.start();

}

/*
@Override
public void onDestroy() {

mNM.cancel(R.string.local_service_started);

// Tell the user we stopped.
Toast.makeText(this, R.string.local_service_stopped, Toast.LENGTH_SHORT).show();
}
*/

@Override
public IBinder onBind(Intent intent)
{
return mBinder;
}




/**
* Show a notification while this service is running.
* @param msg
**/
private void showNotification(String username, String msg)
{
// Set the icon, scrolling text and TIMESTAMP
String title = "کالج: شما یک پیام جدید دارید! (" + username + ")";
//Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
//v.vibrate(1000);
String text = username + ": " +
((msg.length() < 5) ? msg : msg.substring(0, 5)+ "...");

//NotificationCompat.Builder notification = new NotificationCompat.Builder(R.drawable.stat_sample, title,System.currentTimeMillis());
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.stat_sample)
.setContentTitle(title)
.setContentText(text)
.setNumber(++numMessages);

Intent i = new Intent(this, Messaging.class);
i.putExtra(FriendInfo.USERNAME, username);
//i.putExtra(MessageInfo.MESSAGETEXT, msg);

// The PendingIntent to launch our activity if the user selects this notification
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
i, 0);

// Set the info for the views that show in the notification panel.
// msg.length()>15 ? MSG : msg.substring(0, 15);
mBuilder.setContentIntent(contentIntent);

mBuilder.setContentText(" پیام جدید از " + username + ": " + msg);

mNM.notify(notificationID, mBuilder.build());

}

protected void cancelNotification() {
Log.i("Cancel", "notification");
mNM.cancel(notificationID);
}
 و اینو داخل اکتیویتی نوشتم

private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
imService = ((IMService.IMBinder)service).getService();

FriendInfo[] friends = FriendController.getFriendsInfo(); //imService.getLastRawFriendList();
if (friends != null) {
FriendList.this.updateData(friends, null); // parseFriendInfo(friendList);
}

setTitle(imService.getUsername() + "'s friend list");
ownusername = imService.getUsername();
}
@Override
public void onServiceDisconnected(ComponentName className) {
imService = null;
Toast.makeText(FriendList.this, R.string.local_service_stopped,
Toast.LENGTH_SHORT).show();
}
};


@Override
protected void onResume()
{

super.onResume();
bindService(new Intent(FriendList.this, IMService.class), mConnection , Context.BIND_AUTO_CREATE);

IntentFilter i = new IntentFilter();
//i.addAction(IMService.TAKE_MESSAGE);
i.addAction(IMService.FRIEND_LIST_UPDATED);

registerReceiver(messageReceiver, i);


}
0 0
کد های مانیفست رو هم بذار باید هردو رو بذاری ببینیم چیکار کردی؟ (11 سال پیش)
0 0
شما بخش 26-02 Push Notification رو کامل بررسی کردی ؟ ترد استفاده کردی ؟ اول فصل 26 قسمت 2 رو مشاهده کن (11 سال پیش)
+1 0
من برنامه چت دارم مینویسم و برنامم خیلی داره بزرگ میشه!مثلا میخوام صفحه لاگین نشون نده یه راست بره سراغ freindList (11 سال پیش)
0 0
اتفاقا من هم دارم مسنجر می نویسم ، اونطوری نمی شه ؛ 26-2 رو ببین (11 سال پیش)
0 0
خب نرم افزارت امادس؟یا اولاشی؟که اگه دوس داری باهم بنویسیم!http://jahan-ara.ir/chat/college.apk یه نگاه بنداز اگه دوس داشتی باهم کار کنیم (11 سال پیش)
0 0
وسطاشم ، برای استفاده از اسمایل کمی مشکل داشتم توی لایبریش و ... (11 سال پیش)
0 0
من کد نویسیم بنظرم جامع هس!حالا بهرحال دوست داشتین باهم کار میکنیم (11 سال پیش)
0 0
اگر بشه خوشحال می شم (11 سال پیش)
پاسخ به سوال 
سجاد زهره ای  11 سال پیش
0 0

اینم کل مانیفست ببخشید زیاده

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.college.course.app.chat"
android:versionCode="1"
android:versionName="1.1" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE"/>

<application
android:name=".G"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity android:name=".FriendList">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category
android:name="android.intent.category.NORMAL">
</category>
</intent-filter>
</activity>

<service android:name=".services.IMService"></service>
<activity android:name=".Login">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER">
</category>
</intent-filter>
</activity>
<activity android:name=".Messaging">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category
android:name="android.intent.category.NORMAL">
</category>
</intent-filter>
</activity>

<activity android:name=".Update">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category
android:name="android.intent.category.NORMAL">
</category>
</intent-filter>
</activity>
<activity android:name=".Screen"
android:screenOrientation="landscape"></activity>
<activity android:name=".profile.profile"></activity>
<activity android:name=".profile.dashboard"></activity>
<activity android:name=".profile.friendProfile"></activity>
<activity android:name=".listview.MainActivity"></activity>
<activity android:name=".profile.MainActivity1"></activity>
<activity android:name=".profile.MainActivity2"></activity>



<activity android:name=".profile.upload_pic">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category
android:name="android.intent.category.NORMAL">
</category>
</intent-filter>
</activity>



<activity android:name=".SignUp"><intent-filter><action android:name="android.intent.action.MAIN"></action>

<category android:name="android.intent.category.NORMAL"></category>
</intent-filter>
</activity>
<activity android:name=".AddFriend"><intent-filter><action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.NORMAL"></category>
</intent-filter>
</activity>
<activity android:name=".UnApprovedFriendList"><intent-filter><action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.NORMAL"></category>
</intent-filter>
</activity>
</application>


</manifest>

پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .