GVKun编程网logo

delphi – 如何知道为什么’OnCloseQuery’被调用 – MDI子关闭或应用程序关闭?

16

如果您对delphi–如何知道为什么’OnCloseQuery’被调用–MDI子关闭或应用程序关闭?感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解delphi–如何知道为什么’OnCloseQ

如果您对delphi – 如何知道为什么’OnCloseQuery’被调用 – MDI子关闭或应用程序关闭?感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解delphi – 如何知道为什么’OnCloseQuery’被调用 – MDI子关闭或应用程序关闭?的各种细节,此外还有关于android – 何时检测应用程序关闭?、android – 当应用程序关闭或应用程序处于后台时,获取两次GCM PUSH通知、asp.net – 如何知道为什么IIS应用程序池被回收、blackberry – 应用程序在RAM中占用太多空间导致应用程序关闭的实用技巧。

本文目录一览:

delphi – 如何知道为什么’OnCloseQuery’被调用 – MDI子关闭或应用程序关闭?

delphi – 如何知道为什么’OnCloseQuery’被调用 – MDI子关闭或应用程序关闭?

我目前正在开发一个MDI应用程序.
每次创建新的MDI子窗口时,它的基础数据都会动态保存到sqlite数据库,并且打开的列设置为1,因此如果用户关闭程序并重新打开它,则会恢复窗口(以防万一) of Anything BadTM).
因此,每个文档始终存在于数据库中 – 如果用户单击“保存”,则唯一发生的事情是将持久性列设置为1.
现在,如果关闭MDI子窗口,则将open设置为0 – 并且持久性= 0 AND open = 0的每一行都将注定失败并将被删除.

由于这种行为,我不需要问“保存文件?”在ApplicationClose上.
但每次MDI子窗口关闭时我都需要询问.
如果在MDIChild.OnCloseQuery之前调用Mainform.OnCloseQuery,那将很容易做到,但遗憾的是情况并非如此.

把它们加起来:
我需要一种方法来了解是否调用了MDIChild.OnCloseQuery

>应用程序正在关闭,或
> MDI子窗口正在关闭.

有没有办法做到这一点?

解决方法

您需要在主窗体中覆盖受保护的虚方法CloseQuery.当它触发时你知道应用程序正在关闭.但是,在主窗体上触发OnCloseQuery事件之前,继承的实现会在MDI子节点上调用CloseQuery.

这是CloseQuery的TCustomForm实现:

function TCustomForm.CloseQuery: Boolean;
var
  I: Integer;
begin
  if FormStyle = fsMDIForm then
  begin
    Result := False;
    for I := 0 to MDIChildCount - 1 do
      if not MDIChildren[I].CloseQuery then Exit;
  end;
  Result := True;
  if Assigned(FOnCloseQuery) then FOnCloseQuery(Self,Result);
end;

请注意,MDI子项在Self之前获得了CloseQuery通知,即主表单.

因此,在您的主要表单中,您需要:

type
  TMainForm = class(TForm);
  private
    FCloseQueryExecuting: Boolean;
  protected
    function CloseQuery: Boolean; override;
  public
    property CloseQueryExecuting: Boolean read FCloseQueryExecuting;
  end;

然后是一个看起来像这样的实现:

function TMainForm.CloseQuery: Boolean; 
begin
  FCloseQueryExecuting := True;
  try
    Result := inherited CloseQuery;
  finally
    FCloseQueryExecuting := False;
  end;
end;

然后,MDI子项可以在其OnCloseQuery事件中检查主窗体的FCloseQueryExecuting属性的状态.

android – 何时检测应用程序关闭?

android – 何时检测应用程序关闭?

我有一个应用程序,自动将位置数据传输到后台服务器(是的,这是必要的)但需要在活动被销毁时保存内存(即onDestroy()不起作用),但我希望我的应用程序在正在运行的应用程序视图中“刷掉”时终止这些操作.

是否有必要这样做或线程会自动中断?

编辑:我自己学习了服务,但是我将奖励那些使用它们最全面的例子的人. (我自己不需要它,但我认为目前的答案不值得赏心悦目.)

解决方法

yes,this is necessary) but needs to do it while the activity is destroyed to save memory

我觉得你做错了什么.为什么将位置发送到远程对等点以及活动生命周期?我认为没有任何意义.如果您只想在前台时发送位置,则可以使用ActivityLifecycleCallbacks,这样当您进入前台或后台时可以得到通知,当您进入后台时停止单独的发送工作人员,或者当您的活动成为最前端时恢复.

至于最近与列表相关的问题,让我粘贴Dianne Hackborn的评论:

what specifically happens when you swipe away a recent task is it: (1)
kills any background or empty processes of the application (see
07001
for what this means),and (2) uses the new
07002
API to tell any services of the application about the task being
removed so it can do whatever it thinks is appropriate.

你可以在这里找到这篇文章:https://plus.google.com/105051985738280261832/posts/GfwRYCC42uX(我没有找到直接链接谷歌加上评论的方式).

android – 当应用程序关闭或应用程序处于后台时,获取两次GCM PUSH通知

android – 当应用程序关闭或应用程序处于后台时,获取两次GCM PUSH通知

我在我的应用程序中实现了gcm推送通知.一切都很好,我也收到通知.

问题:

>当应用程序处于后台或终止状态时,我一次收到2个通知.
>当应用程序处于前台时,只能获得我想要的1个通知.

App should get only 1 notification as requirement but unfortunately facing undefined situation.

我的代码如下:

用于接收消息的GCmpushReceiverService类.

public class GCmpushReceiverService extends GcmListenerService {

//This method will be called on every new message received
@Override
public void onMessageReceived(String from, Bundle data) {
    //Getting the message from the bundle
    String message = data.getString("message");
    //displaying a notiffication with the message
    Log.e("MeSs",""+message);
    sendNotification(this,message, "traccar App");
    sendNotification(message);

}

//This method is generating a notification and displaying the notification  //When in front
private void sendNotification(Context context, String notificationText,
                              String notificationTitle) {

    PowerManager pm = (PowerManager) context
            .getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(
            PowerManager.PARTIAL_WAKE_LOCK, "");
    wakeLock.acquire();

    Intent intent = new Intent(this, Home.class);
    intent.putExtra("ChatFragment", "newChatFound");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    int requestCode = 0;
    PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_ONE_SHOT);
    Uri sound = ringtoneManager.getDefaultUri(ringtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
            context)
            .setSmallIcon(R.drawable.bug_log_two)
            .setColor(Color.RED)
            .setContentTitle(notificationTitle)
            .setContentText(notificationText)
            .setDefaults(Notification.DEFAULT_ALL)
            .setAutoCancel(true)
            .setContentIntent(pendingIntent);


    notificationmanager notificationmanager = (notificationmanager)getSystemService(Context.NOTIFICATION_SERVICE);

    notificationmanager.notify(0, notificationBuilder.build()); //0 = ID of notification

    wakeLock.release();
}

private void sendNotification(String message) {
    Intent intent = new Intent(this, Home.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    int requestCode = 0;
    PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_ONE_SHOT);
    Uri sound = ringtoneManager.getDefaultUri(ringtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentText(message)
            .setAutoCancel(true)
            .setContentIntent(pendingIntent);

    notificationmanager notificationmanager = (notificationmanager)getSystemService(Context.NOTIFICATION_SERVICE);

    notificationmanager.notify(0, noBuilder.build()); //0 = ID of notification
}

}

清单文件代码:

 <!-- GCM -->

    <receiver
        android:name="com.google.android.gms.gcm.GcmReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />

            <category android:name="com.vk.trackeruser" />
        </intent-filter>
    </receiver>

    <!-- GCM Receiver Service -->
    <service
        android:name=".Notification.GCmpushReceiverService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </service>

    <!-- GCM Registration Intent Service -->
    <service
        android:name=".Notification.GCMRegistrationIntentService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.android.gms.iid.InstanceID" />
        </intent-filter>
    </service>

GCMRegistrationIntentService类:

public class GCMRegistrationIntentService extends IntentService {
//Constants for success and errors
public static final String REGISTRATION_SUCCESS = "RegistrationSuccess";
public static final String REGISTRATION_ERROR = "RegistrationError";
public static final String SenderId = "my id with numeric number ex 9897979";
//Class constructor
public GCMRegistrationIntentService() {
    super("");
}


@Override
protected void onHandleIntent(Intent intent) {
    //Registering gcm to the device
    registerGCM();
}

private void registerGCM() {
    //Registration complete intent initially null
    Intent registrationComplete = null;

    //Register token is also null
    //we will get the token on successfull registration
    String token = null;
    try {
        //Creating an instanceid
        InstanceID instanceID = InstanceID.getInstance(getApplicationContext());

        //Getting the token from the instance id
        token = instanceID.getToken(SenderId, GoogleCloudMessaging.INSTANCE_ID_ScopE, null);

        //displaying the token in the log so that we can copy it to send push notification
        //You can also extend the app by storing the token in to your server
        Log.w("GCMRegIntentService", "token:" + token);
      String  tokan = token;
        //on registration complete creating intent with success
        registrationComplete = new Intent(REGISTRATION_SUCCESS);

        //Putting the token to the intent
        registrationComplete.putExtra("token", token);
    } catch (Exception e) {
        //If any error occurred
        Log.w("GCMRegIntentService", "Registration error");
        registrationComplete = new Intent(REGISTRATION_ERROR);
    }
    //Sending the broadcast that registration is completed
    LocalbroadcastManager.getInstance(this).sendbroadcast(registrationComplete);
}
    }

GCMTokenRefreshListenerService类:

public class GCMTokenRefreshListenerService extends InstanceIDListenerService{
  //If the token is changed registering the device again
    @Override
    public void onTokenRefresh() {
        Intent intent = new Intent(this, GCMRegistrationIntentService.class);
        startService(intent);
    }
}

获取我的GCM令牌的类:

   in oncreate {
    //Initializing our broadcast receiver
    mRegistrationbroadcastReceiver = new broadcastReceiver() {

        //When the broadcast received
        //We are sending the broadcast from GCMRegistrationIntentService

        @Override
        public void onReceive(Context context, Intent intent) {
            //If the broadcast has received with success
            //that means device is registered successfully
            if(intent.getAction().equals(GCMRegistrationIntentService.REGISTRATION_SUCCESS)){
                //Getting the registration token from the intent
                String token = intent.getStringExtra("token");
                StaticContents.Gcm_token=token;
                Log.e("Token",""+token);
                //displaying the token as toast
                Toast.makeText(getApplicationContext(), "Registration token:" + token, Toast.LENGTH_LONG).show();

                //if the intent is not with success then displaying error messages
            } else if(intent.getAction().equals(GCMRegistrationIntentService.REGISTRATION_ERROR)){
                //        Toast.makeText(getApplicationContext(), "GCM registration error!", Toast.LENGTH_LONG).show();
            } else {
                //          Toast.makeText(getApplicationContext(), "Error occurred", Toast.LENGTH_LONG).show();
            }
        }
    };

    //Checking play service is available or not
    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

    //if play service is not available
    if(ConnectionResult.SUCCESS != resultCode) {
        //If play service is supported but not installed
        if(GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
            //displaying message that play service is not installed
            //        Toast.makeText(getApplicationContext(), "Google Play Service is not install/enabled in this device!", Toast.LENGTH_LONG).show();
            GooglePlayServicesUtil.showErrorNotification(resultCode, getApplicationContext());

            //If play service is not supported
            //displaying an error message
        } else {
            //          Toast.makeText(getApplicationContext(), "This device does not support for Google Play Service!", Toast.LENGTH_LONG).show();
        }

        //If play service is available
    } else {
        //Starting intent to register device
        Intent itent = new Intent(this, GCMRegistrationIntentService.class);
        startService(itent);
    }
}
 //Registering receiver on activity resume
@Override
protected void onResume() {
    super.onResume();
    Log.w("MainActivity", "onResume");
    LocalbroadcastManager.getInstance(this).registerReceiver(mRegistrationbroadcastReceiver,
            new IntentFilter(GCMRegistrationIntentService.REGISTRATION_SUCCESS));
    LocalbroadcastManager.getInstance(this).registerReceiver(mRegistrationbroadcastReceiver,
            new IntentFilter(GCMRegistrationIntentService.REGISTRATION_ERROR));
}

    //Unregistering receiver on activity paused
@Override
protected void onPause() {
    super.onPause();

LocalbroadcastManager.getInstance(this).unregisterReceiver(mRegistrationbroadcastReceiver);

}

Output 1: When the app in visible (foreground) only one notification is received.

enter image description here

Output 2: When app is closed or app is in background Getting 2 notifications.

enter image description here

解决方法:

1.一旦从GCM收到消息,就会调用GCmpushReceiverService类中的onMessageReceived函数.

用这个

String message = data.getString("message");

您正在解析并将消息存储在名为message的变量中.

问题是您将消息传递给两个函数

sendNotification(this,message, "traccar App");
sendNotification(message);

这两个函数正在构建一个通知,并将您传递给这两个函数的消息显示为2个单独的通知.

只需注释掉这两个函数中的任何一个并进行检查.

2.为了避免重复通知,有一种方法可以处理它.
尝试改变这个 –

PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_ONE_SHOT);

PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

如果问题仍然存在,请发布您获得的有效负载.我建议使用FCM而不是GCM

asp.net – 如何知道为什么IIS应用程序池被回收

asp.net – 如何知道为什么IIS应用程序池被回收

背景:

我已经部署了一个ASP.NET MVC 3应用程序,在我的机器上工作到一个shared hosting provider,并发现一些似乎与应用程序池被回收有关的问题。主机在以下情况下已将垃圾回收设置发生:

>内存使用量超过200MB
cpu使用率超过75%(大概是持续的时间)
> 20分钟的空闲时间

我的开发机器的限制更为轻松,所以在开发过程中没有看到这样的回收。我没有管理员访问共享托管框(可以理解),所以我无法读取事件日志,以了解为什么这种回收正在发生。

题:

有没有办法我可以找出为什么我的应用程序被回收(例如Application_End),以便我可以记录它来帮助我的调试?

解决方法

无需访问事件日志(因为您处于共享托管环境中),您将要获得的最多信息来自Application_End事件,并通过向HttpRuntime(通过反射)询问一个或两个私有成员的值很遗憾不会公开露面

为此,将以下代码添加到Application_End事件中:

BindingFlags staticFlags = 
    BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField;
BindingFlags instanceFlags = 
    BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField;

HttpRuntime runtime = (HttpRuntime)typeof(System.Web.HttpRuntime)
                        .InvokeMember("_theRuntime",staticFlags,null,null);
if(runtime != null) 
{
    string shutDownMessage = (string)runtime.GetType()
         .InvokeMember("_shutDownMessage",instanceFlags,runtime,null);

    string shutDownStack = (string)runtime.GetType()
         .InvokeMember("_shutDownStack",null);

    // Log shutDownMessage & shutDownStack somewhere
}

如果我关闭或回收我的应用程序的应用程序池,我看到以下内容:

HostingEnvironment initiated shutdown
HostingEnvironment caused shutdown -    
   at System.Environment.GetStackTrace(Exception e,Boolean needFileInfo)
   at System.Environment.get_StackTrace()
   at System.Web.Hosting.HostingEnvironment.InitiateShutdownInternal()
   at System.Web.Hosting.HostingEnvironment.InitiateShutdownWithoutDemand()
   at System.Web.Hosting.PipelineRuntime.StopProcessing()

这可能与获得的一样好。

更新:

我不记得我在哪里找到这个代码,但是Drew有帮助地提醒我,这是从Scott Guthrie博客文章。

还有一些其他的私人会员可能是有用的,如:

private ApplicationShutdownReason _shutdownReason;

您可以检查.NET Reflector中的这些字段(如果您仍然有一个不是时间轰炸的副本)或其他选项(Open Source Alternatives to Reflector?)。

blackberry – 应用程序在RAM中占用太多空间导致应用程序关闭

blackberry – 应用程序在RAM中占用太多空间导致应用程序关闭

我的应用程序有问题我正在构建BB 9800的RAM太小了.

我有一个html5应用程序,我在IOS和BlackBerry中使用.
我正在使用phonegap插件通过使用Sybase来提取数据表单服务器.

在IOS上一切运行正常,但在黑莓上我经常收到“内存不足,请停止应用程序”的消息,并且运行的唯一应用程序是我的.通常接下来是“应用程序关闭,因为它太大了”.

How can I either increase the memory available for my app (unlikely)
or decrease the amount my app is using (tips and guide lines)

我正在使用:

> Sencha Touch为我们的界面
> Phonegap访问原生api
> Sybase在我们的本地数据和服务器数据之间进行同步
>没有工具包 – 只有一个是sencha touch
>一切都在index.html加载 – 根本没有ajax
> index.html是本地文件 – 没有请求加载

Sencha做DOM的东西 – 不是所有屏幕都在一个主要的DOM中 – 屏幕是按需创建的.

解决方法

你提到你从Sybase提取数据 – 当你得到那个内存错误时?

不幸的是,sencha / phonegap / sybase同步/你的js将占用内存(特别是因为它只在一个页面中),而这些框架足以引起麻烦……

我的建议:

>如果只在加载数据时发生错误,问题是您加载了多少数据?也许它试图下载1GB的数据并试图在内存中这样做?我会研究服务器端分页以减少数据占用空间
>尝试拆分成多个.html页面,每个页面都在一个大文件中执行您正在进行的工作的子集…

希望这可以帮助

关于delphi – 如何知道为什么’OnCloseQuery’被调用 – MDI子关闭或应用程序关闭?的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于android – 何时检测应用程序关闭?、android – 当应用程序关闭或应用程序处于后台时,获取两次GCM PUSH通知、asp.net – 如何知道为什么IIS应用程序池被回收、blackberry – 应用程序在RAM中占用太多空间导致应用程序关闭等相关知识的信息别忘了在本站进行查找喔。

本文标签: